从Unix时间戳创建NSDate [英] Create NSDate from Unix timestamp

查看:103
本文介绍了从Unix时间戳创建NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从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.startDateNSDate*.关键字"broadcastStartedTime"的值是由 SBJson转换为NSNumberNSDecimalNumber的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆