iPhone 上的 GMT 时间
如何获取 GMT 时间?
NSDate *c =[NSDate date];
给出系统时间,而不是 GMT。
How do I get GMT time?
NSDate *c =[NSDate date];
gives system time, not GMT.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这是拉明答案的简单版本
This is a simpler version of Ramin's answer
如果出于显示目的,您想显示它,请使用 NSDateFormatter,如下所示:
If it's for display purposes you want to display it, use NSDateFormatter like so:
如果执行日期计算,这些类别可能有用。将日期转换为“标准化”(即,具有相同的月、日和年,但时间为 +1200 UTC),如果您使用也设置为 UTC 的 NSCalendar 执行后续计算 (
+[ NSCalendar normalizedCalendar]
),一切都会解决。If performing date calculations, these categories may be useful. Having converted your date to being 'normalized' (that is, having the same month, day, and year but at +1200 UTC), if you then perform subsequent calculations using an NSCalendar that is also set to UTC (
+[NSCalendar normalizedCalendar]
), it'll all work out.NSDate 在内部存储时区——如果您想要日期的字符串表示形式,您可以调用一些函数并传入目标时区,请参阅 苹果的文档
NSDate stores the time zone internally -- there are a few functions you can call and pass in a target timezone if you jsut want a string representation of the date, see apple's documentation
请参阅:
CFTimeZoneCreateWithTimeIntervalFromGMT
SecondsFromGMT
日期和时间时间编程指南
See:
CFTimeZoneCreateWithTimeIntervalFromGMT
secondsFromGMT
Date & Time Programming Guide