How to find out the current timezone offset on the device in HOURS ?
The JavaScript getTimezoneOffset() method is used to find the timezone offset. It returns the timezone difference in minutes, between the UTC and the current local time. If the returned value is positive, local timezone is behind the UTC and if it is negative, the local timezone if ahead of UTC.
An offset is the number of hours or minutes a certain time zone is ahead of or behind GMT**. A time zone's offset can change throughout the year because of Daylight Saving Time.
UTC Date Format Use DateFormatter to parse and format a date in Swift. The default time zone for a DateFormatter is the device's local time, so to obtain UTC time the timeZone value needs to be configured. let utcDateFormatter = DateFormatter() utcDateFormatter. dateStyle = . medium utcDateFormatter.
There is a very nice NSTimeZone object which will give you the timezone offset from GMT in seconds:
float timezoneoffset = ([[NSTimeZone systemTimeZone] secondsFromGMT] / 3600.0);
For more see blog post
http://blog.indieiphonedev.com/2011/01/09/getting-the-timezone-on-the-device/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With