[Tutor] Converting timestamp read as str to "full date and time"

Juan Christian juan0christian at gmail.com
Sat Sep 20 01:00:49 CEST 2014


Let's say I have ' 1411167038 ' string that I got from an API and I need to
convert it to something like ' Fri, 19 Sep 2014 22:50:38 GMT ' or maybe
even the localtime of the PC.

I'm trying this way:

my_date =
datetime.datetime.fromtimestamp(api['backpack_update'][GAME_ID]).strftime("%D
%H:%M")

The key ' api['backpack_update'][GAME_ID] ' returns exactly what's
expected, the timestamp in string format. But now I need to convert this to
a "full date and time" so that I can print in the terminal/cmd like '
print(my_date) '.

I already read the https://docs.python.org/2/library/datetime.html and I
think that the func 'strptime' may resolve my problem, already tried with
this one, but didn't work.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140919/f969ffdb/attachment.html>


More information about the Tutor mailing list