Python ValueError:时间数据';2016年1月1日00:09:55';与格式不匹配';%m/%d/%y%H:%m:%S'; dt='1/1/2016 00:09:55'#假设是月日年 >>>从日期时间导入日期时间 dtp=datetime.strtime(dt,“%m/%d/%y%H:%m:%S”) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 文件 ValueError:时间数据“1/1/2016 00:09:55”与格式“%m/%d/%y%H:%m:%S”不匹配

Python ValueError:时间数据';2016年1月1日00:09:55';与格式不匹配';%m/%d/%y%H:%m:%S'; dt='1/1/2016 00:09:55'#假设是月日年 >>>从日期时间导入日期时间 dtp=datetime.strtime(dt,“%m/%d/%y%H:%m:%S”) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 文件 ValueError:时间数据“1/1/2016 00:09:55”与格式“%m/%d/%y%H:%m:%S”不匹配,python,Python,如何解析这个时间数据?谢谢。该%y说明符要求使用两位数的年份 >>> dt = '1/1/2016 00:09:55' # It supposes to be month day year >>> from datetime import datetime dtp = datetime.strptime(dt, '%m/%d/%y %H:%M:%S') Traceback (most recent call last): File "<stdin&g

如何解析这个时间数据?谢谢。

%y
说明符要求使用两位数的年份

>>> dt = '1/1/2016 00:09:55' # It supposes to be month day year
>>> from datetime import datetime
dtp = datetime.strptime(dt, '%m/%d/%y %H:%M:%S')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 
ValueError: time data '1/1/2016 00:09:55' does not match format '%m/%d/%y %H:%M:%S'

%y
说明符调用两位数的年份

>>> dt = '1/1/2016 00:09:55' # It supposes to be month day year
>>> from datetime import datetime
dtp = datetime.strptime(dt, '%m/%d/%y %H:%M:%S')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 
ValueError: time data '1/1/2016 00:09:55' does not match format '%m/%d/%y %H:%M:%S'

改用
%Y

>>> datetime.strptime('01/01/16 00:09:17', '%m/%d/%y %H:%M:%S')
datetime.datetime(2016, 1, 1, 0, 9, 17)
输出

dtp = datetime.strptime(dt, '%m/%d/%Y %H:%M:%S')

改用
%Y

>>> datetime.strptime('01/01/16 00:09:17', '%m/%d/%y %H:%M:%S')
datetime.datetime(2016, 1, 1, 0, 9, 17)
输出

dtp = datetime.strptime(dt, '%m/%d/%Y %H:%M:%S')
给出:

文件“C:\Users\achow\Anaconda3\lib\u strtime.py”,第565行,在_strtime\u datetime中 tt,分数=_strtime(数据字符串,格式)

文件“C:\Users\achow\Anaconda3\lib_strtime.py”,第362行,在_strtime中 (数据字符串,格式))

ValueError:时间数据“5/23/2016 17:35”与格式“%m/%d/%Y%H:%m:%S%p”不匹配

按如下方式进行修复:

 date = datetime.strptime(row[0], '%m/%d/%Y %H:%M:%S %p')
给出:

文件“C:\Users\achow\Anaconda3\lib\u strtime.py”,第565行,在_strtime\u datetime中 tt,分数=_strtime(数据字符串,格式)

文件“C:\Users\achow\Anaconda3\lib_strtime.py”,第362行,在_strtime中 (数据字符串,格式))

ValueError:时间数据“5/23/2016 17:35”与格式“%m/%d/%Y%H:%m:%S%p”不匹配

按如下方式进行修复:

 date = datetime.strptime(row[0], '%m/%d/%Y %H:%M:%S %p')