python – 我如何解释与datetime.strptime的周期(AM / PM)?

特别是我有代码,简化到这:

from datetime import datetime
date_string = '2009-11-29 03:17 PM'
format = '%Y-%m-%d %H:%M %p'
my_date = datetime.strptime(date_string, format)

# This prints '2009-11-29 03:17 AM'
print my_date.strftime(format)

是什么赋予了? Python解析日期时是否忽略周期说明符或者我做一些愚蠢的事情?

Python time.strftime docs说:

When used with the strptime() function, the %p directive only
affects the output hour field if the %I directive is used to parse
the hour.

果然,改变你的%H到%我使它的工作。

http://stackoverflow.com/questions/1759455/how-can-i-account-for-period-am-pm-with-datetime-strptime

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:python – 我如何解释与datetime.strptime的周期(AM / PM)?