从 1970 年开始使用 String 时间创建 NSDate

Create NSDate with String time from 1970

我有一个字符串,它的值是时间。时间格式为 "time from 1970"。如何将此字符串转换为 nsdata 对象?

我不明白你所说的 "The time is formatted with 'time from 1970'" 是什么意思,但这里是如何将包含自 1970 年以来的秒数的长格式字符串转换为 NSDate 对象:

NSDate * date = [NSDate dateWithTimeIntervalSince1970:[longValueString longLongValue]];

有时来自服务器的时间以毫秒为单位。在这种情况下,您需要将其除以 1000。

NSDate * date = [NSDate dateWithTimeIntervalSince1970:[longValueString longLongValue]/1000];