How to convert epoch timestamp to human readable date format in Python?

Posted on In QA

How to convert an epoch timestamp to a human readable date format?

In Python:

import time

time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime(epoch))

One example:

$ python
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> epoch = 1490157520.05
>>> time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime(epoch))
'Wed, 22 Mar 2017 12:38:40 HKT'
>>> 

Leave a Reply

Your email address will not be published. Required fields are marked *