I would like to display only the day and month of a date. Basically the NSDateFormatterLongStyle but without the year.
The problem I'm facing is the localization. In the english version it has to show for example 'January 14' and in french '14 Janvier'.
Is there an easy way to print such dates? Or do I have use ifelse statements for checking the current locale and set the day before开发者_StackOverflow中文版 or after the month?
Thanks in advance for your help.
Check out this question.....
I had have the same issue before but have solved it by using the dateFormat
not the dateStyle
This function looks like it will get you most of the way there if not all...
+ (NSString *)dateFormatFromTemplate:(NSString *)templateoptions:(NSUInteger)optslocale:(NSLocale *)locale
http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSDateFormatter_Class/Reference/Reference.html#//apple_ref/occ/clm/NSDateFormatter/dateFormatFromTemplate:options:locale:
"Different locales have different conventions for the ordering of date components. You use this method to get an appropriate format string for a given set of components for a specified locale (typically you use the current locale—see currentLocale)."
I think if you use their example provided, just remove the y from
NSString *dateComponents = @"yMMMMd";
and it will give you a string without the year portion for the given locale
I found this answer: Using NSDateFormatter on the iPhone, protect locale but lose date components
It works great!
It seems like an if/else wouldn't be sufficient to the task of catching every case. I would use the NSDateFormatterLong style, then just find/replace to remove the year from the string.
精彩评论