Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
Get Locale Date Format Information

Using Swift 4, is there a way to get a string representation of a locale's date format? Based on an iPhone's locale settings, I would like to find out if the format is yyyy/mm/dd or mm/dd/yyyy.

I've found all of the ways for changing a date format or getting the date from the locale's format but have not been able to work out how to get the actual format.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use DateFormatter dateFormat(fromTemplate:options:locale:).

let userFormat = DateFormatter.dateFormat(fromTemplate: "yyyyMMdd", options: 0, locale: Locale.current)

In the US this returns MM/dd/yyyy. In Germany this gives dd.MM.yyyy.

If you ever need to get the appropriate time format which also takes into account the user's chosen 12/24-hour time format, use a template of jms. The j is a special format specifier, only used with templates, that returns either h or H for the hour depending on what's appropriate.


Another possible option is to create a DateFormatter, set the desired dateStyle and timeStyle, then read the dateFormat property:

var mydf = DateFormatter()
mydf.dateStyle = .long // set as desired
mydf.timeStyle = .full // set as desired
print(mydf.dateFormat)

For the US this gives:

MMMM d, y 'at' h:mm:ss a zzzz

For Germany this gives:

d. MMMM y 'um' HH:mm:ss zzzz

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!