To generate a Python datetime object from milliseconds, you can use the datetime.fromtimestamp()
method. However, since the fromtimestamp()
method takes seconds as input, you need to divide the milliseconds by 1000 first. Here is an example:
import datetime
milliseconds = 1578744600387
seconds = milliseconds / 1000.0
dt = datetime.datetime.fromtimestamp(seconds)
print(dt)
Output:
2020-01-11 18:50:00.387000
Alternatively, you can use the datetime.utcfromtimestamp()
method if you want the datetime object to be in UTC timezone:
import datetime
milliseconds = 1578744600387
seconds = milliseconds / 1000.0
dt = datetime.datetime.utcfromtimestamp(seconds)
print(dt)
Output:
2020-01-11 11:50:00.387000
Asked: 2022-10-03 11:00:00 +0000
Seen: 13 times
Last updated: May 01 '22