Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get time formatter string for AM / PM without using time

Is there a way to get AM / PM localized string from time formatter without using any given time?

Something like:

let locale = Locale(identifier: "en-us")
        
let formatter = DateFormatter()
formatter.locale = locale
formatter.dateFormat = "a"

and somehow print "am" and "pm" variant.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can get it from Calendar, using the amSymbol and pmSymbol properties.

var calendar = Calendar.current
// set the locale if you want am/pm for a non-current locale
// calendar.locale = someLocale
let am = calendar.amSymbol
let pm = calendar.pmSymbol
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading