Search code examples
objective-cdstnstimezone

Objective C - How to get raw offset (without DST) using NSTimeZone


I'd like to get raw offset from GMT. I know the answer could be like that:

NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"Europe/Berlin"];
NSInteger *offset = [zone secondsFromGMT];

(like here: iOS - How to get raw offset for timezone?)

But the problem is, it doesn't give me raw offset (for Berlin +1), but only offset with DST (+2), that is, for the current date.


Solution

  • NSTimeZone has a property daylightSavingTimeOffset which returns the difference to the raw offset

    NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"Europe/Berlin"];
    NSTimeInterval rawOffset = [zone secondsFromGMT] - [zone daylightSavingTimeOffset];