Mat Mat - 6 months ago 8
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

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.