将ctime转换为unicode,将unicode转换为ctime python

Mic*_*thy 2 python unicode ctime

我已将ctime值转换为unicode

1295478503.6789999至'Wed Jan 19 18:08:23 2011'

我可以倒退吗?从第二行到第一行?

met*_*att 5

你想要Python时间模块,特别是strptime()函数.(你如何从ctime转换为unicode/string?可能是time.strftime().所以有必要寻找它的反方向,即time.strptime().)

以下是Google的一个很好的查询:http://www.google.com/search?q = python + expand + 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
Run Code Online (Sandbox Code Playgroud)