开发者

iPhone CurrentTimeZoneOffset from UTC

开发者 https://www.devze.com 2022-12-17 11:48 出处:网络
Is there a way to get the offset time zone for a given date. For example, if I am in New York and I pass in 12-12-2009 4 PM I would get back \"-4\" as we are 4 hours off GMT.

Is there a way to get the offset time zone for a given date.

For example, if I am in New York and I pass in 12-12-2009 4 PM I would get back "-4" as we are 4 hours off GMT.

(In .NET land there is a function to do that off 开发者_运维技巧the DateTime class. So I'm guess Cocoa has it too?)

Ian


You can use the following:

[[NSTimeZone systemTimeZone] secondsFromGMTForDate:someDate];

This will return the offset in seconds.

See Apple's documentation on the NSTimeZone class for details.


Here is solution in Swift for getting time offset in String

https://gist.github.com/MihaelIsaev/35be147af2bb397d2cf8

0

精彩评论

暂无评论...
验证码 换一张
取 消