什么是Python中time.asctime的反转

时间:2014-04-25 11:10:08

标签: python time

我有一个24个字符的字符串,想要得到元组。

E.g:

'Fri Apr 25 12:24:47 2014'

(通过time.ctime(time.time())

1 个答案:

答案 0 :(得分:1)

time.strptime()再次将字符串解析为时间元组;默认的解析格式与time.ctime()time.asctime()的输出匹配:

>>> import time
>>> time.ctime(time.time())
'Fri Apr 25 12:12:06 2014'
>>> time.strptime(time.ctime(time.time()))
time.struct_time(tm_year=2014, tm_mon=4, tm_mday=25, tm_hour=12, tm_min=12, tm_sec=10, tm_wday=4, tm_yday=115, tm_isdst=-1)
>>> time.strptime(time.asctime())
time.struct_time(tm_year=2014, tm_mon=4, tm_mday=25, tm_hour=12, tm_min=13, tm_sec=6, tm_wday=4, tm_yday=115, tm_isdst=-1)