简体   繁体   中英

How do microseconds work in a datetime.timedelta?

In the example below - I'm getting a value for seconds that do not match the microseconds. It is baffling me. Can anyone shed a light?

>>> a
datetime.datetime(2019, 9, 13, 21, 47, 46, 837435, tzinfo=<UTC>)
>>> b
datetime.datetime(2019, 9, 13, 21, 47, 54, 724570, tzinfo=<UTC>)
>>> (b-a).microseconds
887135
>>> (b-a).seconds
7
>>> (b-a)
datetime.timedelta(seconds=7, microseconds=887135)

Microseconds is not the delta in microseconds, it is the non-integer reminder in microseconds. The time difference is 7 seconds and 887135 microseconds

I just realized that (ba).seconds is not supposed to the equivalent of (ba).microseconds. The exact time difference here is (ba).seconds + (ba).microseconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM