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

359
Vistas
Problem with momentJs using utc and startOf around midnight

I need to have the 00:00 of the current day in utc and timestamp so i do something like that:

moment().utc().startOf('day').valueOf()

I see that somebody suggest to use :

moment.utc().startOf('day').valueOf()

but I didn't find the differences...

Anyway, my problem is another: I work in +1 offset so my problem is when I try to take the midnight (startOf('day')) and the local hour time is between 00:00 and 01:00 I have the midnight of the previous day.

here some console log to be clare:

console.log("test1", moment().format())
>"test1", "2021-11-24T00:21:52+01:00"

console.log("test2", moment.utc().format())
>"test2", "2021-11-23T23:21:52+00:00"

console.log("test3", moment().utc().format())
>"test3", "2021-11-23T23:21:52+00:00"

as you can see if the local time is 00:21 the utc is 23:21 and if I try to keep the startOf('day') I will have as result the midnight of the day before.

console.log("test4", moment().startOf('day').format())
>test4", "2021-11-24T00:00:00+01:00"

console.log("test5", moment().utc().startOf('day').format())
>"test5", "2021-11-23T00:00:00+00:00"

I need to use the UTC and the startOf

How can I resolve the problem to have also the current day if I try to catch it between 00:00 and 01:00? any idea?

and the same problem can be between 00:00 and different time zone not only +1

if for example, I would be in a +2 zone my problem would be shifted between 00:00 and 02:00

Thanks

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