Convert Unix timestamp to Readable Date/time

Discussion in 'Python' started by kaklis, Jul 22, 2010.

  1. kaklis

    kaklis Guest

    Well i have the following number 1279796174846
    i did the following:

    mdate = 1279796174846
    tempStr = str(mdate)
    tempStr2 = tempStr[:-3]
    tempInt = int(tempStr2)
    print "Last Login :", datetime.datetime.fromtimestamp(tempInt)

    that prints out: 2010-07-22 06:56:14
    But when i check my answer at

    i got: Thu, 22 Jul 2010 10:56:14 GMT which is what i want.
    What am i doing wrong?

    kaklis, Jul 22, 2010
    1. Advertisements

  2. kaklis

    Chris Rebert Guest

    classmethod datetime.fromtimestamp(timestamp[, tz])
    Return the ***local*** date and time corresponding to the POSIX
    timestamp [...]
    classmethod datetime.utcfromtimestamp(timestamp)¶
    Return the ***UTC*** datetime corresponding to the POSIX timestamp [...]

    IOW, read the fine docs.

    Chris Rebert, Jul 22, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.