Why can the seconds field understate a multi-day job duration?

A timedelta stores days, seconds and microseconds separately. total_seconds converts the full interval to seconds.

Python example and interpretation

A job lasting one day and two seconds has a seconds field of two but lasts 86402 seconds. Use the full duration in multi-day reports.

from datetime import timedelta
d=timedelta(days=1,seconds=2)
[d.seconds,d.total_seconds()]

Result [2, 86402.0]

中文

多天作业的耗时为何不能直接读 seconds 字段?

timedelta 分开保存天、秒和微秒;total_seconds 将整个时间差换算到秒。

Python 算例与适用条件

作业运行一天零两秒,seconds 只给 2,完整耗时是 86402 秒。跨天报表要取包含天数的值。

from datetime import timedelta
d=timedelta(days=1,seconds=2)
[d.seconds,d.total_seconds()]

结果 [2, 86402.0]

References / 参考来源

Keep reading / 继续阅读