The class datetime.timedoes not support subtraction of objects for the same reason that it does not support comparison of objects, i.e. because its objects may not be define an attribute tzinfo:
, a b, a b . , , TypeError . tzinfo, tzinfo . tzinfo, UTC ( self.utcoffset()). , , TypeError , == ! =. False True.
datetime.datetime, , .
, python, , date.today() datetime.combine.
, , datetime.timedelta, total_seconds(), ( float, ). 10 6 .
from datetime import datetime, date, time
x = time(9, 30, 30, 0)
y = time(9, 30, 31, 100000)
diff = datetime.combine(date.today(), y) - datetime.combine(date.today(), x)
print diff.total_seconds() * (10 ** 6)
timedeltas:
from datetime import timedelta
x = timedelta(hours=9, minutes=30, seconds=30)
y = timedelta(hours=9, minutes=30, seconds=31, microseconds=100000)
print (y - x).total_seconds() * (10 ** 6)