Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

namanhams

macrumors regular
Original poster
Jun 3, 2009
153
0
Here is my code :
Code:
NSString *s = @"Wednesday, 19 January 2011";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"EEEE, dd LLLL yyyy"];
NSDate *date = [df dateFromString:s];
NSLog(@"%@",date);  
NSLog(@"%@",[df stringFromDate:date]);

Here's the output :

2011-01-18 16:00:00 +0000
Wednesday, 19 January 2011


So the 2nd output line is as expected, while the 1st output line is totally strange.
How come it's like that ?
 
Last edited:
NSDate has no locale or time zone associated with it. When you log it like that it logs as if it were in GMT. This was a change, I think in 4.0. Before that it would print the date using your own locale and time zone. You should never use something like printing a date using %@ to show a date to a user. Use the date formatter, and it will give you what you want (once you figure it out).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.