我正在解析一个数组,并想从现在开始清除记录。
我有这个代码:
int i = 0;
for (i=0; i < tempArray.count; i++) {
currentObjectArray = tempArray[i];
NSString *dateString = [currentObjectArray valueForKey:@"ScheduleTime" ];
NSDate *schedule = [dateFormatter dateFromString:dateString];
NSLog(@"schedule: %lu", (unsigned long) schedule );
NSLog(@"now: %lu", (unsigned long)[NSDate date] );
NSTimeInterval distanceBetweenDates = [schedule timeIntervalSinceDate: schedule];
NSLog(@"distanceBetweenDates: %lu", (unsigned long)distanceBetweenDates );
结果:
schedule: 16436914033316069376
now: 6174145184
distanceBetweenDates: 0
但是两个结果数字不正确,因此结果不正确。有人可以告诉我我做错了什么吗?谢谢
更新:感谢下面的答案,我更新了我的代码如下:
NSString *dateString = [currentObjectArray valueForKey:@"ScheduleTime" ];
NSDate *schedule = [dateFormatter dateFromString:dateString];
float s = [schedule timeIntervalSince1970];
NSLog(@" %f", s );
NSTimeInterval timeInterval = [currentObjectArray timeIntervalSinceNow];
if (timeInterval > 0) {
NSLog(@"YES");
} else {
NSLog(@"NO");
The schedule date format is: "YYYY-MM-DD'T'HH:mm:ss"
Update2:我忘了添加当地时区。感谢所有的帮助。