views:

44

answers:

1

I can print out a date nicely based on the user's locale. But how could I get a string with the date+time format?

+1  A: 
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
NSLog(@"The date and time is %@", [formatter stringFromDate:[NSDate date]]);
Darren
Perfect! I was getting an empty string all the time because I didn't explicitely set those styles. wasted 5 hours of my life ;-)
HelloMoon