Django时区当天差异不是0



测试功能

from django.utils import timezone
def date_diff_now(date):
    print(date)
    print(timezone.now())
    print(date - timezone.now())
    print((date - timezone.now()).days)

结果

2018-02-07 17:46:36.442314+00:00
2018-02-07 17:47:32.084900+00:00
-1 day, 23:59:04.357374
-1

为什么同一天2个日期时间之间的区别不返回0?

从基本时间和日期

如果天数的归一化值位于指示范围之外 溢流升起。

请注意,负值的归一化最初可能令人惊讶。 例如,

>>> from datetime import timedelta
>>> d = timedelta(microseconds=-1)
>>> (d.days, d.seconds, d.microseconds)
(-1, 86399, 999999)

因此看起来像已知的溢出错误。

最新更新