code

import datetime
import time
import os

start_run_time="2020-12-11 15:16:08"

print(start_run_time)
#开始时间转为秒级时间戳
ts1=time.mktime(time.strptime(start_run_time, '%Y-%m-%d %H:%M:%S'))

#当前时间
t2=datetime.datetime.now()
#当前日期
ct2 =t2.strftime('%Y-%m-%d %H:%M:%S')
#转为秒级时间戳
ts2=time.mktime(time.strptime(ct2, '%Y-%m-%d %H:%M:%S'))

#计算持续时间
diff_time=(datetime.datetime.fromtimestamp(ts2)-datetime.datetime.fromtimestamp(ts1)).seconds
m, s = divmod(diff_time, 60)
h, m = divmod(m, 60)
res_diff_time="{:02}:{:02}:{:02}".format(h, m, s)
print(res_diff_time)

 

 

 

 

 

 

 

 

 

 

相关文章:

  • 2021-12-26
  • 2021-12-06
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-12-18
猜你喜欢
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案