Python日期时间段由strptime忽略?

时间:2014-07-26 23:29:43

标签: python python-2.7 datetime python-datetime

我正在尝试从字符串中删除datetime对象,但由于某种原因,句点(AM / PM)被忽略。下面是一些示例代码来演示问题:

from datetime import datetime

timeFormat = '%m/%d/%Y %H:%M%p'
amString = "07/26/1994 2:00AM"
pmString = "07/26/1994 2:00PM"

amDate = datetime.strptime(amString, timeFormat)
pmDate = datetime.strptime(pmString, timeFormat)

哪个好 - 但如果我打印每个日期以显示值:

>>> pmDate
datetime.datetime(1994, 7, 26, 2, 0)
>>> amDate
datetime.datetime(1994, 7, 26, 2, 0)
>>> amDate == pmDate
True

我认为amDatepmDate变量应该相等。这是Python 2.7的datetime模块的常见行为还是我遗漏了一些明显的东西?如果对于datetime.strptime这段时间是无效的,为什么?

0 个答案:

没有答案