比较日期的问题 - NSDate
OLD DATE: 2011-04-06 10:58:43 +0000
NEW DATE: 2011-04-06 10:58:43 +0000
我需要比较这两个日期。当新的大于旧的时,这对我来说很重要。但我的问题是我的代码总是进入比较代码块。因此,上面的日期示例因我的应用程序而异,但它们是相同的,我不明白我如何在这里得到错误的结果。这是代码:
Something *existing;
for(existing in exisingDatabaseItems)
{
Something *newFromWebService;
for(newFromWebService in WSArray)
{
if(existing.SomethingId == newFromWebService.SomethingId)
{
if([existing.LastModifiedOnDate compare:newFromWebService.LastModifiedOnDate] == NSOrderedAscending)
{
// It always get in here???
NSLog(@"OLD: %@", existing.LastModifiedOnDate);
NSLog(@"NEW: %@", newFromWebService.LastModifiedOnDate);
break;
}
}
}
}
OLD DATE: 2011-04-06 10:58:43 +0000
NEW DATE: 2011-04-06 10:58:43 +0000
I need to compare this two dates. When new greater than old this is important for me. But I have problem my code always get in that compare code block. So above date examples is different by my application but they are same, I don't understand how I get wrong result here. This is the code:
Something *existing;
for(existing in exisingDatabaseItems)
{
Something *newFromWebService;
for(newFromWebService in WSArray)
{
if(existing.SomethingId == newFromWebService.SomethingId)
{
if([existing.LastModifiedOnDate compare:newFromWebService.LastModifiedOnDate] == NSOrderedAscending)
{
// It always get in here???
NSLog(@"OLD: %@", existing.LastModifiedOnDate);
NSLog(@"NEW: %@", newFromWebService.LastModifiedOnDate);
break;
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保这些日期没有毫秒成分;您的日志记录未显示完整的 UTC。
Make sure those dates don't have millisecond components; your logging is not showing a full UTC.