String到datetime转换中的ValueError

时间:2014-10-12 20:10:08

标签: python

我正在尝试将字符串(我在列表中)转换为日期时间。 我试过这个:

import datetime

list = [
    '12-October-2014-18:30',
    '12-October-2014-19:30',
    '12-October-2014-20:00',
    '12-October-2014-20:30',
    '13-October-2014-00:30',
]

for item in list:
  item_time = datetime.datetime.strptime(item, "%m-%B-%Y-%H-%M")
  print item_time

但是我收到了这个错误:

ValueError: time data '12-October-2014-18:30' does not match format '%m-%B-%Y-%H-%M'

我没有看到错误,有人可以帮忙吗?

1 个答案:

答案 0 :(得分:-1)

有两件事是错的。

'%m-%B-%Y-%H-%M',您的日期应为:'12-October-2014-18-30'

在某些内容中,12th只有12,而18:30所有内容都为18-30,但需要{{1}}