Convert from epoch to human readable date

I was stuck with an issue of converting the epoch time to human readable format, in my case the epoch time was in milli sec, and I was getting all sort of python ValueError: (22, 'Invalid argument')

The fix was simple, to convert the epoch in milli sec to exact date +%s format by slicing [:3]

1
2
3
4
5
import time
time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(epoch))

#Replace time.localtime with time.gmtime for GMT time.

Comments