从Unix时间戳创建NSDate [英] Create NSDate from Unix timestamp
问题描述
如何从Unix时间戳创建NSDate?
How do I create an NSDate from a Unix timestamp?
channel.startDate = [NSDate dateWithTimeIntervalSince1970:
(NSTimeInterval)[channelJson objectForKey:@"broadcastStartedTime"]];
我收到此错误:
104:错误:在以下位置使用了指针值 浮点值是预期的
104: error: pointer value used where a floating point value was expected
channels.startDate
是NSDate*
.关键字"broadcastStartedTime"的值是由 SBJson转换为NSNumber
或NSDecimalNumber
的Javascript Number
解析器库.
channels.startDate
is an NSDate*
. The value for the key "broadcastStartedTime" is a Javascript Number
converted into an NSNumber
or NSDecimalNumber
by the SBJson parser library.
推荐答案
尝试以下方法:
NSNumber *startTime = channelJson[@"broadcastStartedTime"];
channel.startDate = [NSDate dateWithTimeIntervalSince1970:[startTime doubleValue]];
您的值被困在NSNumber
指针类型中. dateWithTimeIntervalSince1970
方法期望使用原始NSTimeInterval
(在幕后是double
).
Your value is trapped in a pointer type of NSNumber
. The dateWithTimeIntervalSince1970
method is expecting a primitive NSTimeInterval
(which, under the covers, is a double
).
这篇关于从Unix时间戳创建NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!