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

390
Visualizações
How to decode js timestamp to python timestamp and vice versa?

I am making a request to one of server and getting response like this:

result = {"object_type": "window_id", 
          "cctv_times" : ['1655375216687000', '1655375216717000', '1655375216717000', '1655375216775000']}

I am not able to understand the time format it is using and if I have to make a post request to that server with the current time, I am unable to convert the python timestamp into that format.

In python, if I convert the current time into a timestamp, it looks like this:

from datetime import datetime

time_now = datetime.now().strftime("%s%f")

This gives me results in something like:

1655375242179881

But in server response, there are already a few zeros at the end even though the time is live from there, what is the format and how to convert python time into that format?

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

0

We know that datetime.now().strftime("%s%f") is a timestamps measured in microseconds (since %s is seconds and %f is microseconds).

And 1655375216687000 and 1655375242179881 are the same length, which suggests your source data is also a timestamp measured in microseconds. (The fact that the last three digits are always 000 suggests that it was originally derived from a source with milliseconds precision, but the value is clearly microseconds).

We can use datetime.fromtimestamp: https://docs.python.org/3/library/datetime.html#datetime.datetime.fromtimestamp

However this expects a time in seconds, "as returned by time.time()"

So we can:

from datetime import datetime

datetime.fromtimestamp(int('1655375216687000') / 1e6)

Which returns datetime.datetime(2022, 6, 16, 11, 26, 56, 687000)

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