iOS NSCalendar NSTimezone daylight saving time confusion

59 Views Asked by At

I am trying to set a date with my default time zone and I would appreciate some clarification regarding the output.

You can see the difference in the NSLog output, the debug timestamp is 11:XX while the output shows 09:XX. My expectations were that the output would show 11:XX too.

NSCalendar *a = [NSCalendar currentCalendar];
    [a setTimeZone:[NSTimeZone defaultTimeZone]];


    NSDateComponents *comps = [[NSDateComponents alloc] init];
    [comps setYear:2013];
    [comps setMonth:9];
    [comps setDay:7];
    [comps setHour:11];
    [comps setMinute:5];

    NSDate *referenceTime = [a dateFromComponents:comps];
    NSLog(@"The time zone %@", [NSTimeZone defaultTimeZone]);
    NSLog(@"The reference time %@", referenceTime);

Output

2013-09-07 11:28:17.467 otest[7145:303] The time zone Europe/Stockholm (GMT+02:00) offset 7200 (Daylight)
2013-09-07 11:28:17.468 otest[7145:303] The reference time 2013-09-07 09:05:00 +0000
0

There are 0 best solutions below