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

Danny Yoo dyoo at hashcollision.org
Sat Sep 20 01:09:50 CEST 2014


On Fri, Sep 19, 2014 at 4:00 PM, Juan Christian
<juan0christian at gmail.com> wrote:
> 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.

What does that number mean though?  Let me guess: is it the number of
seconds since the Epoch?

>>> t = 1411167038
>>> import datetime
>>> datetime.datetime.fromtimestamp(t)
datetime.datetime(2014, 9, 19, 15, 50, 38)

... I think that's what that number means.  It may be the number of
seconds since the Epoch.

References:

    https://docs.python.org/2/library/datetime.html#datetime.datetime.fromtimestamp
    https://docs.python.org/2/library/time.html#time.time


More information about the Tutor mailing list