Python strptime 无法解析日期
Python strptime is unable to parse date
当我尝试 运行 以下代码时,即使据我所知日期遵循指定的格式字符串,我仍然收到值错误。
try:
datetime.datetime.strptime('23-Jan-2017 15:30:00', '%d-%B-%Y %H:%M:%S')
except ValueError as e:
print('Not mathcing')
traceback.print_exc()
我哪里错了?日期和格式与给定的格式字符串匹配,那么我做错了什么?
您需要一个小写的 b 表示月份
'%d-%B-%Y %H:%M:%S'
应该是
'%d-%b-%Y %H:%M:%S'
有关格式值的完整列表,请参阅 here
%b Month as locale’s abbreviated name. Sep
%B Month as locale’s full name. September
您应该写“%b”而不是“%B”:
datetime.datetime.strptime('23-Jan-2017 15:30:00', '%d-%b-%Y %H:%M:%S')
干杯!
当我尝试 运行 以下代码时,即使据我所知日期遵循指定的格式字符串,我仍然收到值错误。
try:
datetime.datetime.strptime('23-Jan-2017 15:30:00', '%d-%B-%Y %H:%M:%S')
except ValueError as e:
print('Not mathcing')
traceback.print_exc()
我哪里错了?日期和格式与给定的格式字符串匹配,那么我做错了什么?
您需要一个小写的 b 表示月份
'%d-%B-%Y %H:%M:%S'
应该是
'%d-%b-%Y %H:%M:%S'
有关格式值的完整列表,请参阅 here
%b Month as locale’s abbreviated name. Sep
%B Month as locale’s full name. September
您应该写“%b”而不是“%B”:
datetime.datetime.strptime('23-Jan-2017 15:30:00', '%d-%b-%Y %H:%M:%S')
干杯!