Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

241
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda