views:

52

answers:

2
NSString *dateString = @"20.10.2010";
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"dd.MM.yyyy"];
[dateFormatter setLocale:[NSLocale currentLocale]];

NSLog(@"%@", [dateFormatter dateFromString:dateString]);

My output is:

2010-10-19 22:00:00 GMT

Why is one day lost?

+3  A: 

Probably because your locale specificies that you're in GMT +2.

That means the given date is interpreted as 2010-10-20 00:00 GMT+2, hence in GMT+0 that's 2010-10-19 22:00.

Georg
ok, how can I change this options? my iphone is completely set up for one locale: keyboard, language and calendar are set for the german language.
Dopamine
@Dopamine: You probably don't want to. Just print the date with your current locale. `[someObject description]` is usually a bad choice to show to a user, because Apple might change it without notice and it's usually used for debugging.
Georg
@Dopamine: If you really want an answer to your question posted in the comments, I'd advise you to create a new question asking specifically how to interpret dates as GMT+0.
Georg
+1  A: 

You not lost 1 day, but 2 hours. But the display is GMT. What do you want to do with your date ? See the reference to change the output formatter

Benoît