from datetime import datetime
# 开始时间
starttime = datetime.now()
import time
time.sleep(5)
# 结束时间
endtime = datetime.now()
time_span = endtime - starttime
print(type(time_span))
print('时间间隔:', time_span.days)
print('时间间隔:', time_span.seconds)
'''
运行结果:
<class 'datetime.timedelta'>
运行时间: 0
运行时间: 5
'''
'''
timedelta中支持的参数:
days: float = ...,
seconds: float = ...,
microseconds: float = ...,?
milliseconds: float = ...,?
minutes: float = ...,
hours: float = ...,
weeks: float = ...,
'''
'''
参考:
https://blog.csdn.net/Datapad/article/details/114930222
'''