Reputation: 776
When I try to get the localizedString
from DateFormatter
, the output is different from the format that the iOS default calendar app shows.
DateFormatter
for US Locale shows (for dateStyle full)
Tuesday, August 15, 2017
where iOS default calendar app shows
Tue, Aug 15, 2017
DateFormatter
for KR Locale shows (for dateStyle full)
2017년 8월 15일 화요일
where iOS default calendar app shows
2017년 8월 15일 (화)
How do I get the localizedString
as shown in the iOS default calendar app? Should I create custom format for all the locale?
Upvotes: 1
Views: 935
Reputation: 318794
None of the standard styles show an abbreviated weekday and month name.
One option would be to use setLocalizedDateFormatFromTemplate
.
let df = DateFormatter()
df.setLocalizedDateFormatFromTemplate("EEEMMMddyyyy")
let string = df.string(from: Date())
Upvotes: 5
Reputation: 7485
Try the following:
let formatter = DateFormatter()
formatter.setLocalizedDateFormatFromTemplate("EEE, MMM dd, yyyy")
print(formatter.string(from: Date()))
Upvotes: 0