code
import time import datetime t1=time.time() time.sleep(5) t2=time.time() print("相差",(datetime.datetime.fromtimestamp(t2)-datetime.datetime.fromtimestamp(t1)).seconds,"秒")
outputs
macname@MacdeMBP Desktop % python3 test.py 相差 5 秒 macname@MacdeMBP Desktop %