[Tutor] Converting timestamp read as str to "full date and time"
Danny Yoo
dyoo at hashcollision.org
Sat Sep 20 01:22:24 CEST 2014
Huh. I should have read your message more closely. Sorry; it's been
one of those days for me, it seems...
Anyway, can you use ctime()? It looks like that might be almost right:
>>> t = 1411167038
>>> datetime.datetime.utcfromtimestamp(t).ctime()
'Fri Sep 19 22:50:38 2014'
though if you really do want more control over what's being printed,
yes, strftime() is what's you're looking for, I think:
>>> t = 1411167038
>>> datetime.datetime.utcfromtimestamp(t).strftime("%a, %d %b %Y %H:%M:%S")
'Fri, 19 Sep 2014 22:50:38'
https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
More information about the Tutor
mailing list