我有日期功能。我必须将之前的日期与iphone中的当前数据进行比较
对于当前日期,我有代码: -
NSDate* date = [NSDate date];
//Create the dateformatter object
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
//Set the required date format
[formatter setDateFormat:@"yyyy-MM-dd"];
//Get the string date
NSString* str = [formatter stringFromDate:date];
//Display on the console
NSLog(str);
//Set in the lable
[dateLabel setText:str];
但我想实施比较当前日期&在iPhone上的上一个日期
提前致谢
答案 0 :(得分:2)
您可以使用NSDate的比较方法比较日期:
- (NSDate *)earlierDate:(NSDate *)anotherDate;
- (NSDate *)laterDate:(NSDate *)anotherDate;
- (NSComparisonResult)compare:(NSDate *)other;
- (BOOL)isEqualToDate:(NSDate *)otherDate;
检查NSDate class reference了解更多信息..