简体   繁体   English

Python 时间数据 '2008-01-24T00:00:00:000' 与格式 '%Y-%m-%d %H:%M :%S:%f' 不匹配

[英]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.

相关问题 ValueError: 时间数据 &#39;2013/05/24 07:00:00&#39; 与格式 &#39;%Y-%m-%d %H:%M:%S&#39; 不匹配 - ValueError: time data '2013/05/24 07:00:00' does not match format '%Y-%m-%d %H:%M:%S' ValueError:时间数据&#39;0000-00-00 00:00:00&#39;与格式&#39;%Y-%m-%d%H:%M:%S&#39;不匹配 - ValueError: time data '0000-00-00 00:00:00' does not match format '%Y-%m-%d %H:%M:%S' ValueError: 时间数据 &#39;2020-01-31T15:16:21+00:00&#39; 与格式 &#39;%Y-%m-%dT%H:%M:%S%z&#39; 不匹配 - ValueError: time data '2020-01-31T15:16:21+00:00' does not match format '%Y-%m-%dT%H:%M:%S%z' twint 发布时间数据“2020–04–29 00:00:00”与格式“%Y-%m-%d %H:%M:%S”不匹配 - twint issue time data '2020–04–29 00:00:00' does not match format '%Y-%m-%d %H:%M:%S' 时间数据“2021-03-31 23:30:00”与格式“%Y-%m-%d %H:%M:S”不匹配 - time data '2021-03-31 23:30:00' does not match format '%Y-%m-%d %H:%M:S' ValueError:时间数据&#39;2012-07-19 08:24:00&#39;与格式&#39;%Y-%m-%d H:M:S&#39;不匹配 - ValueError: time data '2012-07-19 08:24:00' does not match format '%Y-%m-%d H:M:S' Python/Odoo:ValueError:时间数据“%Y-%m-%d”与格式“2020-10-09 00:00:0)”不匹配 - Python/Odoo: ValueError: time data '%Y-%m-%d' does not match format '2020-10-09 00:00:0)' 我有一个错误提示 ValueError: time data '31 days, 0:00:00' does not match format '%Y-%m-%d' - I have an error that says ValueError: time data '31 days, 0:00:00' does not match format '%Y-%m-%d' ValueError: 时间数据 &#39;2021-11-05 10:13:46+11:00&#39; 与格式 &#39;%y-%m-%d %H:%M:%S%z&#39; 不匹配 - ValueError: time data '2021-11-05 10:13:46+11:00' does not match format '%y-%m-%d %H:%M:%S%z' 时间数据“2019-06-02T16:19:27.000-04:00”与格式“%Y-%m-%dT%H:%M:%S.%fZ”不匹配 - time data '2019-06-02T16:19:27.000-04:00' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM