2020年4月28日星期二

python datetime计算时间差

from datetime import datetime
begin = datetime.strptime('00:01:00.000', '%H:%M:%S.%f')
end = datetime.strptime('00:01:00.002', '%H:%M:%S.%f')
duration = begin - end
duration.total_seconds()  // duration.seconds只计算秒的部分,duration.microseconds只计算毫秒的部分。计算时间差使用total_seconds