Python “time” Module
>>> import time
>>> now = time.strftime("%Y-%m-%d %H:%M:%S")
>>> now
'2009-10-28 14:10:52'
>>> tup = time.strptime(now, "%Y-%m-%d %H:%M:%S")
>>> tup
(2009, 10, 28, 14, 10, 52, 2, 301, -1)
>>> unix = time.mktime(tup)
>>> unix
1256710252.0
>>> tup2 = time.gmtime(unix)
>>> tup2 == tup
False
>>> tup
(2009, 10, 28, 14, 10, 52, 2, 301, -1)
>>> tup2
(2009, 10, 28, 6, 10, 52, 2, 301, 0)
>>> time.strftime("%Y-%m-%d %H:%M:%S", tup)
'2009-10-28 06:10:52'
>>> time.strftime("%Y-%m-%d %H:%M:%S", tup2)
'2009-10-28 06:10:52'
Like this:
Like Loading...
Related
This entry was posted on 28. October 2009 by Xyldrae. It was filed under Information Technology and was tagged with gmtime, mktime, python, strftime, strptime, time.
Leave a Reply