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

326
Visualizações
In NodeJs, why is the new Date constructor setting default time to 7am?

I am defining a new Date object: const date = new Date(2020, 09, 11); The documentation says that the default time for the constructor is: hours : 0, minutes : 0, seconds : 0... etc. However, the result I get is:

const date = new Date(2020, 09, 11);
console.log(date);
2020-10-11T07:00:00.000Z

Why is the hour 7?

When I put the following into the console:

const date2 = new Date(2020, 09, 11, -7)
console.log(date2)
2020-10-11T00:00:00.000Z

I'm at a bit of a loss here.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

That Z at the end stands for Zulu time = GMT. Since your difference is -7 I presume you are located at US Pacific Time. It's telling you that YOUR midnight is at 7am in the UK.

Javascript internally keeps track of time in UTC. The reason for this is to simplify global time synchronization with other users on the internet.

To display your local time do:

console.log(date.toLocaleString());

See also this answer to a related question: How to initialize a JavaScript Date to a particular time zone

about 4 years ago · Juan Pablo Isaza Relatório

0

The displayed time is correct, but in a different time zone. The standard timezone in most programming languages is called UTC (Universal Time Coordinated), GMT (Greenwich Mean Time) or Zulu Time. You can see it by the "Z" at the end of your time string. According to the local setup on your computer you can use date.toLocaleString() --> But even here problems can arise, when your users did set their computer/browser time to a different timezone. You can let your users set their timezones themselves and give these parameters to toLocaleString() according to https://www.w3schools.com/jsref/jsref_tolocalestring.asp

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