views:

51

answers:

1

While working with NSDate, sometimes the time zones are different. But I don't mess around with locales or time zone settings at all.

i.e. sometimes (in the same process) an NSDate object may look like

1.4.2010 22:01:47 +0100

and sometimes like

1.4.2010 22:01:47 +0200

without me doing anything. What triggers the change in time zone? I think that calendaric calculations (i.e. adding 5 months to a date) should not do that, right?

+3  A: 

It is adjusting for daylight savings time. On my machine:

NSDate *now=[NSDate date];
NSDate *notNow=[now dateByAddingTimeInterval:(86400 * 250)]; // add 250 days
NSLog(@"%@", now);
NSLog(@"%@", notNow);

outputs

2010-04-02 17:03:25.386 so[14786:a0f] 2010-04-02 17:03:25 +0100
2010-04-02 17:03:25.388 so[14786:a0f] 2010-12-08 16:03:25 +0000

This is just a display formatting thing that happens on the (hidden) call to [date description].

invariant
interesting. I've never been thinking about shifting timezones when it comes to daylight saving time. good to know.
dontWatchMyProfile