schmidt9
schmidt9

Reputation: 4528

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.

Upvotes: 0

Views: 1140

Answers (1)

vadian
vadian

Reputation: 285072

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];

Upvotes: 5

Related Questions