If 语句比较两个日期
如果文件超过 24 小时,我会尝试自动更新 plist 文件,但我不知道如何比较两个日期。
// get last modification date
NSString *dir = path;
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:dir error:nil];
NSDate *date = [attributes fileModificationDate];
NSDate *fileModPlus24Hours = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:date];
思考这样的事情:
if (date > fileModPlus24Hours) {
// update file
}
有什么建议吗?
Im trying to update a plist file automaticlly if the file is over 24 hours old, but i cant figure out how to compare the two dates.
// get last modification date
NSString *dir = path;
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:dir error:nil];
NSDate *date = [attributes fileModificationDate];
NSDate *fileModPlus24Hours = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:date];
Thinking about something like:
if (date > fileModPlus24Hours) {
// update file
}
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
比较的结果可以是
NSOrderedAscending
、NSOrderedDescending
或NSOrderedSame
。而且我认为通过将
date
与fileModPlus24Hours
进行比较,您的代码也不起作用。您应该将当前日期与fileModPlus24Hours
进行比较:The result of compare can be
NSOrderedAscending
,NSOrderedDescending
orNSOrderedSame
.And I don't think your code will work either by comparing
date
tofileModPlus24Hours
. You should be comparing the current date tofileModPlus24Hours
instead: