Reputation: 1403
I want to display a date in the following way:
I am trying something to get something similar to how the date is displayed in the iPhone SMS application.
Upvotes: 0
Views: 118
Reputation: 2660
why no use the method of
setDoesRelativeDateFormatting:
with it set to YES. Now the formatter now will return 'today' or 'yesterday' or 'tomorrow' depending on the date that should be formatted. If a relative format can't be found, then use the formatter will be used for the format.
Upvotes: 1
Reputation: 2276
For more format patterns as below:
Upvotes: 1
Reputation: 3117
Go through NSDateFormatter
(link here) and NSDate
(link here) class documentation before asking a thing you have not even tried.
The NSDateFormatter
class can be used to properly format the date into your choice with fixed parameters for different components of the date. For showing the full name of the day, use 'cccc' in the format. For eg
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setFormat:@"cccc dd-MM, HH:mm:ss"];
To compare dates, there are in built methods for comparing NSDate
objects for eg isEqualToDate
, laterDate:
, timeIntervalSinceNow
etc. Go through the Apple documentation link
Upvotes: 0