This can't be too difficult..
I want to display a date without the year. For example: "Aug, 2nd" (USA) or "02.08." (GERMANY) It must work for a bunch of other locales as well.
My only idea so far is to do a normal format with year, and then remove the year-portion from the generated string.
The two examples you give are very different from each other. One uses the abbreviated month name while the other uses the 2-digit month number. One uses a day ordinal ("2nd") while the other simply uses the 2-digit day number.
If you can accept using the same general format for all locales then make use of
NSDateFormatter dateFormatFromTemplate:options:locale:
.The result of this call will give back a format string you can use with
NSDateFormatter setDateFormat:
. The order of the month and day will be appropriate for the locale as well as any additional punctuation that should be added.But again, this won't solve your exact needs because of the completely different formats you appear to want for each locale.
I think you need to take a look at:
As per the docs:
Extra code (add this to the code above):
See here: NSDateFormatter Class Reference
Swift 3
Play with
template
to match your needs.Doc and examples here to help you determine the template you want.