python将单个数字日和月转换为两位数

Jef*_*ley 3 python datetime

我正在尝试阅读并将以下日期"6/5/2014 00:09:32"时间转换为"Mon Mar 09 07:07:18 +0000 2015".

d = datetime.datetime.strptime('6/5/2014 00:09:32', '%d/%m/%y %H:%M:%S')
Run Code Online (Sandbox Code Playgroud)

给我一个追溯:

ValueError: time data '6/5/2014 00:00:07' does not match format '%d/%m/%y %H:%M:%S'
Run Code Online (Sandbox Code Playgroud)

我尝试使用%e作为单位数天,如下所示:http://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html#index-strftime-2660,但是datetime只是说出来了不承认'e'.

除非我遗漏了一些东西,看起来像个位数日和月是我的问题,但是从文档(https://docs.python.org/2/library/time.html#time.strftime)我看不到让python的日期时间读取单个数字天或月的方法.但这看起来很傻.我错过了什么?

谢谢您的帮助.

EdC*_*ica 6

你需要'Y'不是'y':

In [412]:

d = dt.datetime.strptime('6/5/2014 00:09:32', '%d/%m/%Y %H:%M:%S')
d
Out[412]:
datetime.datetime(2014, 5, 6, 0, 9, 32)
Run Code Online (Sandbox Code Playgroud)

从文档'Y'对应:

年份以世纪为十进制数.

你试过的'y'是:

没有世纪的年份作为十进制数[00,99].