Python 根据起始时间和结束时间计算时长
生活随笔
收集整理的這篇文章主要介紹了
Python 根据起始时间和结束时间计算时长
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Python 根據起始時間和結束時間計算時長
flyfish
%Y-%m-%d #年月日 大寫Y年是4位 2021-01-01
%y-%m-%d #年月日 小寫y年是兩位 21-01-01
%H:%M:%S #時分秒
參考
代碼實現
import datetime # begin = '08:01:34' # end = '21:59:46' begin = '2021-01-01' end = '22-01-01'# datebegin = datetime.datetime.strptime(begin,"%H:%M:%S") # dateend = datetime.datetime.strptime(end,"%H:%M:%S")datebegin = datetime.datetime.strptime(begin,"%Y-%m-%d") dateend = datetime.datetime.strptime(end,"%y-%m-%d") print(datebegin) print(dateend) diff = dateend - datebegin print(diff.total_seconds()/60/60/24) #print(diff.total_seconds()/60/60)總結
以上是生活随笔為你收集整理的Python 根据起始时间和结束时间计算时长的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 手机epub阅读软件推荐
- 下一篇: Java编程基础二:java基本语法