Why can I not convert the following timestamp?
from datetime import date
timestamp = date.fromtimestamp(1571266800000000000)
print("Date =", timestamp)
https://www.epochconverter.com/ gives the right result.
Why can I not convert the following timestamp?
from datetime import date
timestamp = date.fromtimestamp(1571266800000000000)
print("Date =", timestamp)
https://www.epochconverter.com/ gives the right result.
Besides the nanoseconds, there is another caveat here: If I run
from datetime import date
timestamp = date.fromtimestamp(1571266800000000000/1e9)
print("Date =", timestamp)
>>> Date = 2019-10-17
note that this gives me the date in my local timezone (UTC+2). However, if you expect the date to refer to UTC (since seconds since the epoch should refer to UTC), you need to set the tzinfo
property:
from datetime import datetime, timezone
timestamp = datetime.fromtimestamp(1571266800000000000/1e9, tz=timezone.utc)
print("Date =", timestamp.date())
>>> Date = 2019-10-16
Python expects seconds. The epochconverter gives me
Assuming that this timestamp is in nanoseconds (1 billionth of a second): GMT: Wednesday, 16. October 2019 23:00:00 Your time zone: Donnerstag, 17. Oktober 2019 01:00:00 GMT+02:00 DST Relative: 9 months ago
So I think what you should use in Python is:
date.fromtimestamp(15712668)