gpt4 book ai didi

ios - Rails 日期为 NSDate

转载 作者:行者123 更新时间:2023-11-29 10:36:26 24 4
gpt4 key购买 nike

我正在尝试将日期从 rails api 转换为 NSDate 对象。来自 api 的响应日期是 2014-11-05T16:29:09.614Z.614Z 是什么意思?

最佳答案

Z前的整数是毫秒,Z代表时区的Zulu:

来自 http://en.wikipedia.org/wiki/Coordinated_Universal_Time :

The UTC time zone is sometimes denoted by the letter Z—a reference to the equivalent nautical time zone (GMT), which has been denoted by a Z since about 1950. The letter also refers to the "zone description" of zero hours, which has been used since 1920 (see time zone history). Since the NATO phonetic alphabet and amateur radio word for Z is "Zulu", UTC is sometimes known as Zulu time.

因此你的时间格式是:

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];

如果您在上面的示例中包含 Z,日期将正确转换为设备当前时区。

关于ios - Rails 日期为 NSDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26803180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com