Python datetime模块 计算时间差

import time
from datetime import datetime 

st = datetime.now()
time.sleep(5)
ft = datetime.now()
diff = str ((ft - st).total_seconds())#精确到微秒的时间差
print("diff : " + diff)

diff1 = str ((ft - st).days)#天数差值
print("diff1 : " + diff1)

diff2 = str ((ft - st).seconds)#精确到秒数的时间差
print("diff2 : " + diff2)

diff3 = str ((ft - st).microseconds)#只保留小数点后的时间差(也就是只有微秒的时间差)
print("diff3 : " + diff3)

上一篇:MangoDB基础架构学习笔记


下一篇:Salesforce Consumer Goods Cloud 浅谈篇一之基础介绍