gpt4 book ai didi

python - 无法在 Python 中解析日期

转载 作者:太空宇宙 更新时间:2023-11-04 07:09:58 25 4
gpt4 key购买 nike

我需要解析日期和时间。这是我得到的:

import time
a = time.strptime('Apr 28 2013 23:01', "%b %d %y %H:%M")
print a

但它给了我

Traceback (most recent call last):
File "/home/aaa/Documents/python_test.py", line 17, in <module>
a = time.strptime('Apr 28 2013 23:01', "%b %d %y %H:%M")
File "/usr/lib/python2.7/_strptime.py", line 467, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/lib/python2.7/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data 'Apr 28 2013 23:01' does not match format '%b %d %y %H:%M'

我做错了什么?

最佳答案

%y 对于 4 位数年份应该是 %Y...

来自docs :

%y  Year without century as a decimal number [00,99].    
%Y Year with century as a decimal number.

关于python - 无法在 Python 中解析日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16355437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com