Mat Mat - 1 year ago 84
Objective-C Question

How do I get the current date?

How can I get the current date, and format it like "20/12/2010"?

Answer Source

Use NSDate and NSDateFormatter.

NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSString *dateString = [dateFormat stringFromDate:today];
NSLog(@"date: %@", dateString);

See also.

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