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

146
Vistas
How to handle UTC math using date-fns library in Node?

I'm trying to use the date-fns library to add and subtract dates, but it doesn't handle UTC dates correctly. For example:

> const { add } = require('date-fns');
undefined
> s = new Date('2021-03-27')
2021-03-27T00:00:00.000Z
> add(s, {days:1})
2021-03-28T00:00:00.000Z
> add(s, {days:2})
2021-03-28T23:00:00.000Z

The issue is that my dates are in UTC, and I want to do UTC date arithmetic on them, but as soon as they're converted to a date/time they get treated as local dates. This is a problem. How can I solve this?

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

0

You can make all your operations, and at the end of your function, call the method toISOString() of the final date object. It'll return the UTC 0 value.

And remember that the date object you've passed by parameter to add function is never changed, the returned value is what you want.

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