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

181
Visualizações
Why are python and javascript showing different timestamp for the same date

Below is the javscript code that I am using to get the timestamp of a particular date I got it from here

var myDate = "12-11-2021";
myDate = myDate.split("-");
var newDate = new Date(myDate[2], myDate[1] - 1, myDate[0]);
console.log(newDate.getTime());

The output is 1636655400000

and below is the python code I am using to get the timestamp I got it from the first comment and the accepted answer

datetime.strptime('2021-11-12', '%Y-%m-%d').timestamp()*1000

The outout 1636675200000.0

Why are the two timestamps different ?

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

0

You are calling the Date constructor with these parameters:

var newDate = new Date('2021', '11', '12');

Which is basically representing the date 2021-12-12 and NOT 2021-11-12 as you would expect.

The reason is that in JS the month is zero-based, meaning 0 is January up to 11 for December.

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