Last active
October 13, 2020 19:34
-
-
Save dfrobison/6743baa20e9aa0336109c868c7c2c597 to your computer and use it in GitHub Desktop.
[Localizing Dates] By setting the format with setLocalizedDateFormatFromTemplate(_:) instead, the formatter will do the right thing based on the locale you give it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let dateFormatter = DateFormatter() | |
dateFormatter.locale = Locale(identifier: "en_US") | |
dateFormatter.setLocalizedDateFormatFromTemplate("MMddyyyy") | |
dateFormatter.string(from: Date()) // US: 09/27/2020 | |
// ... | |
dateFormatter.locale = Locale(identifier: "es_BO") | |
dateFormatter.setLocalizedDateFormatFromTemplate("MMddyyyy") | |
dateFormatter.string(from: Date()) // Bolivia: 27/09/2020 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment