Safari Safari - 1 year ago 82
Objective-C Question

get time and date by NSDate

how can I retrieve the date and time from a NSDate.
I want to see them separately.

Answer Source
NSDate *localDate = [NSDate date];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc]init]autorelease];
dateFormatter.dateFormat = @"MM/dd/yy";

NSString *dateString = [dateFormatter stringFromDate: localDate];

NSDateFormatter *timeFormatter = [[[NSDateFormatter alloc]init]autorelease];
timeFormatter.dateFormat = @"HH:mm:ss";

NSString *dateString = [timeFormatter stringFromDate: localDate];

There are many many different ways to represent the date and time so check NSDateFormatter for more info.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download