ziggy ziggy - 1 year ago 163
Python Question

Python convert timestampMS to date

using python 2.7 I have timestampMS ex:

timestampMs 1478001612891

I want to convert it to a date format.

I have tried

but get this error

Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ValueError: timestamp out of range for platform localtime()/gmtime() function

Answer Source

datetime.fromtimestamp expects input in seconds. Divide your number by 1000.0 before passing it in.

(From the specifications: datetime.fromtimestamp(timestamp) will return the local date corresponding to the POSIX timestamp, such as is returned by time.time(). And time.time() will return the time in seconds since the epoch as a floating point number.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download