我正在尝试从字符串中删除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
我认为不的amDate
和pmDate
变量应该相等。这是Python 2.7的datetime
模块的常见行为还是我遗漏了一些明显的东西?如果对于datetime.strptime
这段时间是无效的,为什么?