I have a list of Unix timestamps that I want to convert into UTC time:
times = [..., "1371605102000", "1375245962000", ...]
However, these times are in milliseconds. I tried this code:
from datetime import datetime
import tzlocal
unix_timestamp = float("1371605102000")
local_timezone = tzlocal.get_localzone()
local_time = datetime.fromtimestamp(unix_timestamp, local_timezone)
print(local_time.strftime("%B %d %Y"))
But it threw up this error:
Traceback (most recent call last):
File "temp.py", line 6, in <module>
local_time = datetime.fromtimestamp(unix_timestamp, local_timezone)
ValueError: year 45434 is out of range
I feel like it has to do with the fact that the timestamp is in milliseconds, but I'm not entirely sure.
Other than that, I was also wondering if there was a way to format the dates to something like this:
...
Jan 04, 2017
Oct 27, 2016
...
Rather than this:
...
January 4, 2017
October 27, 2016
....