我正在尝试实现dropBox同步,需要比较两个文件的日期.一个在我的dropBox帐户上,一个在我的iPhone上.
我想出了以下内容,但我得到了意想不到的结果.我想在比较这两个日期时我做了一些根本错误的事情.我只是使用了> <运算符,但我想这并不好,因为我正在比较两个NSDate字符串.开始了:
NSLog(@"dB...lastModified: %@", dbObject.lastModifiedDate);
NSLog(@"iP...lastModified: %@", [self getDateOfLocalFile:@"NoteBook.txt"]);
if ([dbObject lastModifiedDate] < [self getDateOfLocalFile:@"NoteBook.txt"]) {
NSLog(@"...db is more up-to-date. Download in progress...");
[self DBdownload:@"NoteBook.txt"];
NSLog(@"Download complete.");
} else {
NSLog(@"...iP is more up-to-date. Upload in progress...");
[self DBupload:@"NoteBook.txt"];
NSLog(@"Upload complete.");
}
Run Code Online (Sandbox Code Playgroud)
这给了我以下(随机和错误)输出:
2011-05-11 14:20:54.413 NotePage[6918:207] dB...lastModified: 2011-05-11 13:18:25 +0000
2011-05-11 14:20:54.414 NotePage[6918:207] iP...lastModified: 2011-05-11 13:20:48 +0000
2011-05-11 14:20:54.415 NotePage[6918:207] ...db is more up-to-date.
Run Code Online (Sandbox Code Playgroud)
或者这个恰好是正确的:
2011-05-11 14:20:25.097 NotePage[6903:207] dB...lastModified: 2011-05-11 13:18:25 +0000
2011-05-11 14:20:25.098 NotePage[6903:207] iP...lastModified: 2011-05-11 13:19:45 +0000 …Run Code Online (Sandbox Code Playgroud) 我有两个日期:2009-05-11和当前日期.我想检查给定日期是否是当前日期.这怎么可能.