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

218
Vistas
date-fns.format() is not working in safari browser

I am using the date-fns npm package for some date utility. Everything is working fine in the chrome browser. but in mac-safari it's not working. Here is my code snap...

const format = require('date-fns/format');
const parseISO = require('date-fns/parseISO');

const startDateInput = "2020-11-20T09:30:00.000Z";

const formattedStartDate = new Date(format(parseISO(startDateInput), 'MM-dd-yyyy'));
const formattedTodayDate = new Date(format(new Date(), "yyyy-MM-dd"))

console.log('formattedStartDate', formattedStartDate);//IN MAC SAFARI --> Invalid Date 
console.log('formattedTodayDate date1', formattedTodayDate);//IN MAC SAFARI --> Invalid Date 

The same console in chrome is giving Fri Nov 20 2020 18:30:00 GMT+0530 (India Standard Time) a valid date.

Not getting what is the issue with safari browser?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think you don't need the format function if you just want a Date(), and you don't need to do new Date() either

This should work :

const startDate = parseISO(startDateInput);

Now you should have a valid Date object since date-fns will handle the ISO 8601 for you

if you want to format it :

const formattedStartDate = format(startDate, 'yyyy-MM-dd')

Here you have a date string, like 2022-05-05, you should just keep it as a string, use it where you need and you should not use it with new Date() because it will not work in safari

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