您正在比较datetime对象和date对象; datetime.strptime() 总是产生一个datetime实例; 即使时间设置为午夜,这仍然是日期和时间的组合.
要仅比较日期,您需要明确地进行比较.
或者:
date1.date() == date2 # extract the date, compare to the other date
Run Code Online (Sandbox Code Playgroud)
要么
from datetime import time
# compare the datetime to another datetime with midnight
date1 == datetime.combine(date2, time.min)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
108 次 |
| 最近记录: |