I have a string representing a unix timestamp (i.e. "1284101485") in Python, and I'd like to convert it to a readable date. time.strftime returns me with a type error. Any help is appreciated!
A:
Did you look at the datetime package? I believe it has a fromUnixTimestamp method.
extraneon
2010-09-10 06:58:42
It doesn't, but datetime.datetime.fromtimestamp(1284101485) produces datetime.datetime(2010, 9, 10, 8, 51, 25).
Anthony Labarre
2010-09-10 07:01:36
That's what I meant:)
extraneon
2010-09-10 13:26:17
+6
A:
>>> from datetime import datetime
>>> datetime.fromtimestamp(1172969203.1)
datetime.datetime(2007, 3, 4, 0, 46, 43, 100000)
Taken from http://seehuhn.de/pages/pdate
Daniel
2010-09-10 06:59:57
+2
A:
Use datetime
module:
import datetime
print(datetime.datetime.fromtimestamp(int("1284101485")).strftime('%Y-%m-%d %H:%M:%S'))
Michał Niklas
2010-09-10 07:09:25
A:
>>> import time
>>> time.ctime(int("1284101485"))
'Fri Sep 10 16:51:25 2010'
>>> time.strftime("%D %H:%M", time.localtime(int("1284101485")))
'09/10/10 16:51'
gnibbler
2010-09-10 08:28:06