【问题标题】:NSDateFormatter converts timeNSDateFormatter 转换时间
【发布时间】:2012-11-02 17:27:50
【问题描述】:

我有 NSDate 与 (2012-11-14 08:08:16 +0000) 并想显示小时、分钟和秒。

所以我使用了 NSDateFormatter

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm:ss aaa"];

我的电话时间是(10:08:16),但我想显示的不是电话时间,而是我拥有的 NSDate,但是之后

[dateFormatter stringFromDate:myDate]

它给了我 10:08:16 但我想要 08:08:16 我怎么能显示时间?

谢谢。

【问题讨论】:

  • 所以你想用UTC而不是本地时间来显示时间?
  • 嗯,是的,我从服务器获取 UTC 时间并想显示它

标签: objective-c ios5 nsdate nsdateformatter


【解决方案1】:

如果您想显示原始时间 (UTC),请手动设置时区:

[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];

应该可以的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-02
    • 2018-03-01
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多