如何获得目标c中的当前时区

har*_*yap 3 cocoa objective-c

我需要为当前位置获取时区,例如-5或+3等等.我无法这样做.我使用的是datecomponents:

// Turn the date into Integers
NSInteger year = [dateComponents year];
NSInteger month = [dateComponents month];
NSInteger day = [dateComponents day];
Run Code Online (Sandbox Code Playgroud)

Aar*_*ers 6

NSDateFormatter *date_formater=[[NSDateFormatter alloc]init];
[date_formater setDateFormat:@"Z"];
NSString * tz=[date_formater stringFromDate:[NSDate date]];
Run Code Online (Sandbox Code Playgroud)

  • 谢谢亚伦!我还发现tzsecs =([[NSTimeZone localTimeZone] secondsFromGMT])/ 3600; (5认同)