Alex Rivera | Logout

How do I get the current date?

Asked 2010-01-20T13:34:19.353
22

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

Edit
Report

1 Answer

41

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.

answered 2010-01-20T13:39:22.167

Your Answer