iPhone:Find the current timezone offset in HOURS

后端 未结 8 702
萌比男神i
萌比男神i 2021-02-05 03:11

How to find out the current timezone offset on the device in HOURS ?

8条回答
  •  终归单人心
    2021-02-05 03:59

    Don't use an int!!! I copied this code and now have a bug in my app. Some timezones are .5 hrs

    use this:

    float offset = [timezone secondsFromGMTForDate:self.date] / 3600.0;
    

    and don't forget the .0 behind 3600

提交回复
热议问题