//-------compare date
------------------------///
NSDate *today = [NSDate date]; // it will give you current
date
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"MM/dd/yyyy"];
NSDate *todayFormat = [format dateFromString:[format stringFromDate:today]]; // your date
NSComparisonResult result;
//has three
possible values: NSOrderedSame,NSOrderedDescending, NSOrderedAscending
result = [todayFormat compare:historyDate]; // comparing two dates
NSString *dateString;
if(result==NSOrderedAscending
|| result==NSOrderedDescending){
[format setDateFormat:@"EEEE MMM dd yyyy"];
dateString = [format stringFromDate:historyDate];
}else{
dateString = @"Today";
}
No comments:
Post a Comment
Add your comment