I have the date function.And I have to compare the previous date with current data in iphone
For current date I have code:-
NSDate* date = [NSDate date];
//Create the dateformatter object
NSDa开发者_如何学PythonteFormatter* 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];
But I want to implement the compare the current date & previous date in iphone
Thanks in advance
You can compare dates using NSDate's comparison methods:
- (NSDate *)earlierDate:(NSDate *)anotherDate;
- (NSDate *)laterDate:(NSDate *)anotherDate;
- (NSComparisonResult)compare:(NSDate *)other;
- (BOOL)isEqualToDate:(NSDate *)otherDate;
Check NSDate class reference to know more..
精彩评论