Last Updated: February 25, 2016
· purak

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'))

2 Responses
Add your response

Alistair macdonald distance medley

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

over 1 year ago ·
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 ·