ios - 如何从 NSDate iOS 获取 UTC 时间

标签 ios objective-c timezone nsdate

我想在我的 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/

相关文章:

ios - 什么是 PBItemCollectionServicer?

qt - 如何在Qt中设置时区?

java - 如何设置java.util.Date的时区?

ios - 如何显示带有日期的时区缩写

ios - 为什么对象在 NSTimer 失效后重置?

objective-c - 在 iOS6 中处理旋转

ios - clang : error: linker command failed with exit code 1 when archiving

ios - 点击自定义注释并执行相应的功能

iphone - ios 6 : issue - Two-stage rotation animation is deprecated. 这个应用应该使用更流畅的单阶段动画

ios - 仅要求 iAP 购买一次