apple use it in the messages app for today messages Today 11:45 AM Yesterday 11:45 AM
i see it in the apple developer site
To specify a custom fixed format for a date formatter, you use setDateFormat:. The format string uses the format patterns from the Unicode Technical Standard #35. The version of the standard varies with release of the operating system:
Calendar Fields
fields ( alias | (field*, special*)) > field ( alias | (displayName?, relative*, special*)) >
Translations may be supplied for names of calendar fields (elements of a calendar, such as Day, Month, Year, Hour, and so on), and for relative values for those fields (for example, the day with relative value -1 is "Yesterday"). Where there is not a convenient, customary word or phrase in a particular language for a relative value, it should be omitted.
how to use it in Xcode?
Thread Safety On earlier versions of the operating system, or when using the legacy formatter behavior or running in 32-bit in macOS, NSDateFormatter is not thread safe, and you therefore must not mutate a date formatter simultaneously from multiple threads.
The NSDate class provides methods for comparing dates, calculating the time interval between two dates, and creating a new date from a time interval relative to another date.
In most cases the best locale to choose is "en_US_POSIX", a locale that's specifically designed to yield US English results regardless of both user and system preferences.
Your dateFormat in ListViewRow is E, dd MMM yyyy , whereas your date is in format E, dd MMM yyyy HH:mm:ss z . You must convert your date using this dateFormat. You can then use the date object to get a string in your desired format.
use – setDoesRelativeDateFormatting:
NSDateFormatter *dateFormatter = [NSDateFormatter new]; dateFormatter.dateStyle = NSDateFormatterShortStyle; dateFormatter.timeStyle = NSDateFormatterShortStyle; dateFormatter.doesRelativeDateFormatting = YES; NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);
this logs Today, 11:30 AM
on en_US locales.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With