-1

我正在尝试使用 dateWithTimeIntervalSince1970 创建一个 NSDate,但我不断收到 NSInvalidArgumentException。我无法弄清楚我的语法有什么问题:

// [mutableItem valueForKey:@"date"] is a string which represents an integer of milliseconds

NSDate *dateObject = [NSDate dateWithTimeIntervalSince1970:([[mutableItem valueForKey:@"date"] longLongValue]/1000)];

谁能看到这有什么问题?

4

2 回答 2

1

如果除以 1000,则除以整数。如果你除以 1000。(DOT)那么它可能会起作用。

dateWithTimeIntervalSince1970:需要一个双精度的 NSTimeInterval。

于 2012-08-15T09:22:36.237 回答
0

你能检查你的 mutableItem 值吗?

这是我的工作示例:

NSString *mutableItem = @"1344981600000";

NSDate *dateObject = [NSDate dateWithTimeIntervalSince1970:([mutableItem longLongValue]/1000)];

//dateObject = 2012-08-14 22:00:00 +0000
于 2012-08-15T09:35:30.967 回答