目标C-如何使用NSTimeZone获取原始偏移量(无DST) [英] Objective C - How to get raw offset (without DST) using NSTimeZone

查看:94
本文介绍了目标C-如何使用NSTimeZone获取原始偏移量(无DST)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从格林尼治标准时间(GMT)获得原始补偿.我知道答案可能是这样的:

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

(例如此处: iOS-如何获取时区的原始偏移量?)

但是问题是,它没有给我原始偏移量(对于柏林+1),而只有 DST偏移量(+ 2),也就是说,当前日期.

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.

推荐答案

NSTimeZone具有属性daylightSavingTimeOffset,该属性将差值返回到原始偏移量

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

这篇关于目标C-如何使用NSTimeZone获取原始偏移量(无DST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆