IPhone CurrentTimeZoneOffset from UTC

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

For example, if I am in New York and I pass 12-12-2009 at 16:00, I will return “-4” as we are 4 hours from GMT.

(There is a function in the .NET environment to do this outside the DateTime class. So I think Cocoa is there too?)

Yang

+7
timezone datetime iphone gmt offset
source share
2 answers

You can use the following:

[[NSTimeZone systemTimeZone] secondsFromGMTForDate:someDate]; 

This will return the offset in seconds.

See Apple documentation for the NSTimeZone class for more information .

+5
source share

Here is a solution in Swift to get time offset in String

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

0
source share

All Articles