I want to know which is this date format Friday, December 18th
and also is this standard date format or i have to some hard work to get this.
Thanks.
I want to know which is this date format Friday, December 18th
and also is this standard date format or i have to some hard work to get this.
Thanks.
@Robin Help with NSDateFormatter is something which will help u a lot in this case of
NSDateFormatter
, you really have to work hard to get this format,Just see the link i had shared with you.Good Luck!
If it would be possible to post long comments in a readable way I would comment on Madhups answer.
So here is my comment:
The bad thing with those custom date formats is that if you are not from the united states or another country that uses the same dateformat the date is wrong.
This is how your solution would look on my device: Freitag, Februar 18th
My mother would say
th
? What does that mean?And I would say "Another developer that has never left his country."
Please I want my date like this: Freitag, 18. Februar
Because this is what I'm used to. This is how a date should look like.
so please add a check that only uses custom date formatters if the current locale is similar to the custom dateformat you are using.
In iOS4 Apple introduced a really cool method.
+ (NSString *)dateFormatFromTemplate:(NSString *)template options:(NSUInteger)opts locale:(NSLocale *)locale
you pass this method every component you want in your dateformat and you get back a format that uses the locale.
So if you want to use the weekday, the day and the month you would use something like this:
and it would return
EEEE, d. MMMM
for a german locale. OrEEEE, MMMM d
for the us locale. You can then use that to set a custom dateFormat.That's the whole point of NSDateFormatter. Localized dates. If you use
[dateFormatter setDateFormat:@"some hard coded date format"]
to show dates to the user you are doing it wrong in most cases.I really hate apps that mix US date style and german date style.
I don't think the th is possible to achieve via formatters. Although you can do it like this: