【发布时间】:2014-03-12 17:59:13
【问题描述】:
我正在尝试使用 NSTimeInterval 来找出我的 iOS 应用程序中两个时间戳之间的差异。但是,当我尝试传递我的时间戳时,我收到以下错误:
错误的接收器类型'double'
这是我的代码:
// Get the current date/time in timestamp format.
NSString *timestamp = [NSString stringWithFormat:@"%f", [[NSDate new] timeIntervalSince1970]];
double current = [timestamp doubleValue];
// Find difference between current timestamp and
// the timestamp returned in the JSON file.
NSTimeInterval difference = [current timeIntervalSinceDate:1296748524];
我认为 NSTimeInterval 只是 double 的另一个含义..不是吗?
请注意,'1296748524' 在这里仅用作测试。
我不明白我做错了什么。
谢谢你的时间:)
【问题讨论】:
-
你为什么要转换成字符串来做区别?
标签: ios nsdate unix-timestamp nstimeinterval difference