【问题标题】:Strange behavior with NSPredicate and NSDateNSPredicate 和 NSDate 的奇怪行为
【发布时间】:2014-03-21 12:22:06
【问题描述】:

我正在尝试使用 NSPredicate 过滤结果,但我在 NSPredicate 中使用 NSDate 时出现了奇怪的行为。

这里是代码;

NSDate *auctionDate = obj[@"auctionDate"];
NSLog(@"%@", auctionDate);
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"auctionDate == %@", auctionDate];
NSLog(@"%@", predicate);

这是 NSLog 输出;

2014-02-21 00:00:00 +0000
auctionDate == CAST(414633600.000000, "NSDate")

如您所见,每个 NSLog 都显示 NSDate 和 NSPredicate 字符串,但如果仔细观察,NSPredicate 创建的 NSDate 和 UNIX 时间戳并不相等。

414633600.0 转换为日期为“Mon, 21 Feb 1983 00:00:00 GMT”,不等于原始 NSDate。

有什么想法吗?

提前致谢

【问题讨论】:

标签: ios timestamp nsdate nspredicate behavior


【解决方案1】:

NSDate 使用的参考日期是2001 年 1 月 1 日,格林威治标准时间

不是 1970 年。

【讨论】:

  • 嗯,感谢您的回复。但是我如何更正日期? “auctionDate”是从 Parse 服务器获取的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-24
  • 2011-03-05
相关资源
最近更新 更多