Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一系列日期。我将数组 (B) 的对象与控件 (A) 进行比较。与 A 相比,我如何检查 B 的年龄是否为 10 天?理想情况下,我希望能够将变量声明为天数差异。谢谢。
此 Python 代码模板将以天为单位计算差异:
import datetime d1 = datetime.datetime(2012, 7, 1) d2 = datetime.datetime(2012, 7, 5) diff = d2 - d1 print diff.days
两个datetime.datetime对象的差异是一个datetime.timedelta对象。它的.days属性以天为单位为您提供长度。
datetime.datetime
datetime.timedelta
.days