Is it possible to get localized string from date only with month and day?
let localizedDate = DateFormatter.localizedString(from: date, dateStyle: .medium, timeStyle: .none)
This prints Sept 15, 2017
or 15 Sep 2017
.
I would like to honor user's date format and not display the year, only month and day. I mean Sept 15
or 15 Sep
. Is it possible?
You can create a formate for just the day and the month and use that to create a format template. The DateFormatter will then localise it. As an example from an (Xcode9) playground:
If you pass in
Locale.current
to the templateFormatter instead of the example ones I created, then you will get the localised versions of your template.Your question asks about short month format so you can replace "MMMM" in the custom format with "MMM" to get the shortened month name displayed instead of the full one. and a "d" instead of "dd" to not have leading "0" in the date. I'm sure you know what I mean.