2011-01-20 61 views

回答

5

你想Python時間模塊,特別是strptime()函數。 (你是怎麼從ctime轉換爲unicode/string的?可能是用time.strftime()。所以尋找它的反向是time.strptime()。)

這是一個很好的谷歌查詢此,太:http://www.google.com/search?q=python+parse+time+string

樣品:

entropy:~>python 
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import time 
>>> u = u'Wed Jan 19 18:08:23 2011' 
>>> t = time.strptime(u) 
>>> t 
time.struct_time(tm_year=2011, tm_mon=1, tm_mday=19, tm_hour=18, tm_min=8, tm_sec=23, tm_wday=2, tm_yday=19, tm_isdst=-1) 
>>> time.mktime(t) 
1295489303.0 
4
import time 
time.mktime(time.strptime('Wed Jan 19 18:08:23 2011'))