Convert Unix timestamp to Readable Date/time

K

kaklis

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 http://www.onlineconversion.com/unix_time.htm

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

Antonis
 
C

Chris Rebert

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 http://www.onlineconversion.com/unix_time.htm

i got:    Thu, 22 Jul 2010 10:56:14 GMT which is what i want.
What am i doing wrong?
"""
classmethod datetime.fromtimestamp(timestamp[, tz])
Return the ***local*** date and time corresponding to the POSIX
timestamp [...]
"""
vs.
"""
classmethod datetime.utcfromtimestamp(timestamp)¶
Return the ***UTC*** datetime corresponding to the POSIX timestamp [...]
"""

IOW, read the fine docs.

Cheers,
Chris
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top