I have a string representing a unix timestamp (i.e. "1284101485") in Python, and I'd like to convert it to a readable date. When I use time.strftime
, I get a TypeError
:
>>>import time
>>>print time.strftime("%B %d %Y", "1284101485")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument must be 9-item sequence, not str
You can convert the current time like this
To convert a date in string to different formats.
Other than using time/datetime package, pandas can also be used to solve the same problem.Here is how we can use pandas to convert timestamp to readable date:
Timestamps can be in two formats:
13 digits(milliseconds) - To convert milliseconds to date, use:
10 digits(seconds) - To convert seconds to date, use:
Taken from http://seehuhn.de/pages/pdate
For a human readable timestamp from a UNIX timestamp, I have used this in scripts before:
Output:
'December 26, 2012'
quick and dirty one liner:
'2013-5-5-1-9-43'
i just successfully used: