0

I am receiving this time through an API:

1644256800000

then I do:

from datetime import datetime, timezone
datetime.fromtimestamp(1644256800000, timezone.utc)

and it returns the error: {OSError}[Errno 22] Invalid argument. Then if I remove 2 zeroes from the number:

from datetime import datetime, timezone
datetime.fromtimestamp(16442568000, timezone.utc)

the value goes through and returns the result: 2491-01-16 07:00:00 something like 400 years later.

What is the wrong part?

martineau
  • 119,623
  • 25
  • 170
  • 301
Joe Almore
  • 4,036
  • 9
  • 52
  • 77
  • 4
    Likely millisecond epoch time vs seconds. What date do you think it is? – dawg Feb 07 '22 at 18:35
  • if what @dawg is saying is true, then you can do what's listed here: https://stackoverflow.com/a/748534/1366439 divide by 1000.0 – CBredlow Feb 07 '22 at 18:36
  • `datetime.datetime.fromtimestamp(1644256800000/1000.0)` is `datetime.datetime(2022, 2, 7, 13, 0)` – dawg Feb 07 '22 at 18:39
  • 1
    @dawg You're right. It just needed to be divided by 1000. Problem solved. – Joe Almore Feb 07 '22 at 18:51
  • 1
    Beware the Y2038 problem -- that is the end of time with 32 bit epoch stamp. With 64 bits we can represent up to year 292277026596 which is 20x greater than the age of the universe. – dawg Feb 07 '22 at 19:24

0 Answers0