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

旧时模样 提交于 2019-12-13 07:51:16

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/31987925/objective-c-how-to-get-raw-offset-without-dst-using-nstimezone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!