我想在我的 iOS 应用程序中记录服务器时间,我正在使用 NHNetworkTime 库来获取网络时间,当我尝试打印以下显示 GMT 的代码时,通过我选择的 UTC,如何打印日期时间在 UTC 中?
NSDate* datetime = [NSDate networkDate];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; // Prevent adjustment to user's local time zone.
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS Z z "];
NSString* dateTimeInIsoFormatForZuluTimeZone = [dateFormatter stringFromDate:datetime];
NSLog(@"%@",dateTimeInIsoFormatForZuluTimeZone);
this is printing 2016-03-09 06:51:23.406 +0000 GMT
最佳答案
协调世界时 (UTC) 和格林威治标准时间 (GMT) 之间没有时差。您可以从这里获得更多信息More info
关于ios - 如何从 NSDate iOS 获取 UTC 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35885011/