(The day part isn't working, I have trouble getting the "date From Template" & "time Style" to work at the same time.) NSString *date Components = @"eee"; formatter=NSDate Formatter alloc] init]; Style=NSDate Formatter Short Style; [formatter set Date Format:[NSDate Formatter date Format From Template:date Components options:0 locale:[NSLocale autoupdating Current Locale]; Relative Date Formatting=YES; formatter.locale=[NSLocale autoupdating Current Locale]; NSDate Formatter alone won't do it.Probably NSCalendar components:from Date:to Date: is what you want.
I want to get a particular format for my date in my i OS app. I want to display the date with the following format if the text was received less than a week ago: "Today, PM" "Yesterday, AM" "Monday, PM" etc. I've tried few combinations without success, the main problem reside in the first part; Today/yesterday, etc. But, unless you're all tied up in matching the locale or some such, it's a fairly simple matter to just write some code to do it.See Data Formatting Guide for more information about working with formatters.I assume reader is already familiar with basic internationalization facilities and approaches used in i OS apps development.You can inspect a locale by reading its properties, as listed in Getting Information About a Locale.For properties containing a code or identifier, you can then obtain a string suitable for presentation to the user with the methods listed in Getting Display Information About a Locale.Rather, you should limit yourself to setting date and time styles (via ).
On the other hand, if you're working with fixed-format dates, you should first set the locale of the date formatter to something appropriate for your fixed format.
Once you've set "en_US_POSIX" as the locale of the date formatter, you can then set the date format string and the date formatter will behave consistently for all users.
date string, using a fixed date format string and UTC as the time zone.
It is easy to implement one yourself, if you take a look at NSDate Components.
However, there are some nifty libraries to do this.
You might think autoupdateing Current Locale is the prefer way, it is per Apple documentation; however, since the returned object may be cached, you don't really need to hold on to it indefinitely when using current Locale, verse autoupdateing Current Locale.