Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Convert Unix timestamp to Readable Date/time

Reply
Thread Tools

Convert Unix timestamp to Readable Date/time

 
 
kaklis@gmail.com
Guest
Posts: n/a
 
      07-22-2010
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
 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      07-22-2010
On Thu, Jul 22, 2010 at 5:54 AM, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
> 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?


>From http://docs.python.org/library/datetime.html (emphases added):

"""
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
--
http://blog.rebertia.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert unix timestamp to date/time in a specified format Andyza ASP General 6 03-05-2009 12:24 AM
Convert date/time to unix timestamp? Phillip B Oldham Python 2 02-10-2009 01:25 PM
how to convert date to unix timestamp Fibre Optic C++ 1 02-23-2007 12:30 PM
Unix Timestamp Shahid Juma ASP .Net 0 07-05-2005 05:15 PM
Julian timestamp to readable format Satish C Programming 2 10-11-2004 02:07 AM



Advertisments