iPhone:Find the current timezone offset in HOURS

后端 未结 8 675
萌比男神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:42

    For anyone looking for the current time zone offset as a string, try:

    NSDateFormatter *localTimeZoneFormatter = [NSDateFormatter new];
    localTimeZoneFormatter.timeZone = [NSTimeZone localTimeZone];
    localTimeZoneFormatter.dateFormat = @"Z";
    NSString *localTimeZoneOffset = [localTimeZoneFormatter stringFromDate:[NSDate date]];
    

    In my time zone, localTimeZoneOffset contains -0700

提交回复
热议问题