-uuawg
Last Updated: February 25, 2016
·
26.97K
· purak
Fe0a1519fcf6d2efd7f1a0bbc20660d2

How do I convert a unix timestamp to human readable format in Python?

Like this:

import datetime
timestamp = 1339521878.04 
value = datetime.datetime.fromtimestamp(timestamp)
print(value.strftime('%Y-%m-%d %H:%M:%S'))
Say Thanks
Respond

2 Responses
Add your response

21437
Alistair macdonald distance medley

When trying this, I got: "AttributeError: 'module' object has no attribute 'struct_time'"

over 1 year ago ·
21438
Alistair macdonald distance medley

Actually, your code ran fine on another box. Maybe be an issue with a Python installation in VirtualEnv that I ran into.

over 1 year ago ·