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

212
Vistas
How to fix 'Invalid date' on IOS using native Date object or using date-fns?

I have an issue related to rendering date of content within my react application. I've got a date in a format '2021-11-24 20:17:39' from back-end, then I transformed it using the following function:

const getDate = (myDate) =>  
   new Date(myDate).toLocaleDateString(navigator.language, {
   month: 'short',
   day: 'numeric',
   year: 'numeric', 

as a result I got proper date format on every browser on my laptop, like Nov 24, 2021, but the issue was that on IOS I got 'Invalid date' instead of the date I need. Later on, I changed my approach and used the following code:

import { intlFormat } from 'date-fns';

    const getDate = (date) => {
       const userLocale =
       navigator.languages && navigator.languages.length
         ? navigator.languages[0]
         : navigator.language;
    return intlFormat(
       new Date(date),
      {
        month: 'short',
        day: 'numeric',
        year: 'numeric',
      },
     {
        locale: userLocale,
     }
   );
 };

So now the page crushes every time I open it (on IOS) Any ideas would be helpful! p.s. I need exactly this format as a result: Nov 24, 2021. And depending on user browser's location

about 4 years ago · Juan Pablo Isaza
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