How to convert epoch timestamp to human readable date format?

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

asked Apr 2 by zma (2,200 points)

2 Answers

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'
answered Apr 2 by zma (2,200 points)

In Bash, you can use the date command's -d option:

date -d @<your epoch>

Here @ specifies the epoch timestamp.

One example:

$ date -d @1490157520.05
Wed Mar 22 12:38:40 HKT 2017
answered Apr 2 by zma (2,200 points)

Please log in or register to answer this question.

Related questions

7 answers
asked Mar 31 by zma (2,200 points)
0 answers
0 answers
0 answers
0 answers
asked Apr 10 by anonymous
Welcome to Do This In Various Langs (dtivl), where you can ask questions and receive solutions in various programming languages.
Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost