[英]Python time data '2008-01-24T00:00:00:000' does not match format '%Y-%m-%d %H:%M :%S:%f'
I'm trying to take this dictionary, and convert the value of the key 'tow_date' to datetime and then print the month.我正在尝试使用这本字典,并将键 'tow_date' 的值转换为 datetime,然后打印月份。 I've been trying to browse similar questions to no avail.
我一直在尝试浏览类似的问题,但无济于事。 Help?
帮助? But, I keep getting the error below.
但是,我不断收到以下错误。 I'd really appreciate the help.
我真的很感激你的帮助。 Thank you.
谢谢你。
Code:代码:
d=[{'unique_key':'200801247RON', 'tow_date':'2008-01-24T00:00:00:000'}]
x=d[0]['tow_date']
y = datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S:%f")
print(y.month())
Error:错误:
Traceback (most recent call last):
File "main.py", line 17, in <module>
y = datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S:%f")
File "/usr/lib/python3.4/_strptime.py", line 500, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/usr/lib/python3.4/_strptime.py", line 337, in _strptime
(data_string, format))
ValueError: time data '2008-01-24T00:00:00:000' does not match format '%Y-%m-%d %H:%M
:%S:%f'
You're missing a T
, do the following:您缺少
T
,请执行以下操作:
y = datetime.datetime.strptime(x, "%Y-%m-%dT%H:%M:%S:%f")
y.month
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.