我已将ctime值转换为unicode
1295478503.6789999 至 'Wed Jan 19 18:08:23 2011'
我可以倒退吗? 从第二行到第一行?
答案 0 :(得分:5)
您需要Python时间模块,特别是strptime()函数。 (你如何从ctime转换为unicode / string?可能与time.strftime()。所以寻找反方向是有意义的,这是time.strptime()。)
以下是Google的一个很好的查询: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
答案 1 :(得分:4)
import time
time.mktime(time.strptime('Wed Jan 19 18:08:23 2011'))