如何将毫秒时间戳转换为iOS / XCode中的date和时间?

我有一个时间戳,以毫秒为单位,从1970年1月1日00:00:00 UTC开始。

例如。 input“takeoffTime”:以date格式输出“1396614600000”

您可以通过执行以下操作来完成此操作:

[NSDate dateWithTimeIntervalSince1970:1396614600000/1000];

这会给你2014-04-04 12:30:00 +0000 。 您应该阅读如何在这里传递消息(调用方法): 如何在Objective-C中调用方法?

NSDate类给你这个方法+ (instancetype)dateWithTimeIntervalSince1970:(NSTimeInterval)seconds

看这里: 苹果文档

 NSString* takeOffTime = @"1396614600000"; double miliSec = takeOffTime.doubleValue; NSDate* takeOffDate = [NSDate dateWithTimeIntervalSince1970:miliSec/1000];