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

252
Visualizações
Converting Unix timestamp to date time - different results for JS and Python

I have sqlite log file where date is in timestamp.

The conversion with JS by following function gives the correct result

var unixTsToDate = function (UNIX_Timestamp){
var date = new Date(UNIX_Timestamp / 1000);
return date;
};

unixTsToDate (1615370972685000) = Wed Mar 10 2021 11:09:32 GMT+0100

Now I'm trying to to the same with Python 3.9 and it aborts with Error

import datetime
print(datetime.datetime.utcfromtimestamp(1615370972685000))

result:
print(datetime.datetime.utcfromtimestamp(1615370972685000))
OSError: [Errno 22] Invalid argument

The number seems too big for the function. Tried with /1000 (found in internet that could be different timestamps with milliseconds and without), no result

What could be a solution for Python in the case?

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

0

Your timestamp value has microsecond resolution.

51 years (since epoch) * 365 * 24 * 3600 will give roughly 1.6 billion seconds. Your value has additional 6 digits.

So in Python divide by 1000000 instead of 1000.

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