My application provides a list of messages, each of which has a creation date.
I donβt want to just show the date, but show different formats depending on how much time has passed since the creation date.
For example, this is how I create a date string from a date:
NSDate *date = someMessage.creationDate; NSTimeInterval timePassed = [[NSDate date] timeIntervalSinceDate:date]; if (timePassed < 60 ) { // less then one minute return @"now" } else if (timePassed < 3600) { // less then one hour NSInteger minutes = (NSInteger) floor(timePassed / 60.0); return [NSString stringWithFormat:@"%d minutes ago", minutes]; }
Now I want to add the following cases:
else if ("timePassed < 24 hours ago and within the same calendar day") // do something } else if ("timePassed > 24 hours, or within previous calendar day") { // do something else }
but not sure how to do this, any help would be appreciated
Mario source share