Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

365
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda