(1)在程式啟動時獲得當前時間:
recordTime=time.time()
(2)同時獲得當前時間的格式化串:
startTime=time.strftime("%H%M%S")
(3)在主迴圈中按秒進行判斷:
timeGap=time.time()-recordTime
iftimeGap>=1:#這是按1秒設定的,可以根據實際需要設定
recordTime+=timeGap
showTime_String=get_lapseTime(startTime,time.strftime("%H%M%S"))
(4)函式:
defget_lapseTime(aTime,bTime):
aNum=3600*int(aTime[:2])+60*int(aTime[2:4])+int(aTime[-2:])
bNum=3600*int(bTime[:2])+60*int(bTime[2:4])+int(bTime[-2:])
gapH=(bNum-aNum)//3600
gapM=((bNum-aNum)%3600)//60
gapS=((bNum-aNum)%3600)%60
gapTime="%02d:%02d:%02d"%(gapH,gapM,gapS)
return(gapTime)
(1)在程式啟動時獲得當前時間:
recordTime=time.time()
(2)同時獲得當前時間的格式化串:
startTime=time.strftime("%H%M%S")
(3)在主迴圈中按秒進行判斷:
timeGap=time.time()-recordTime
iftimeGap>=1:#這是按1秒設定的,可以根據實際需要設定
recordTime+=timeGap
showTime_String=get_lapseTime(startTime,time.strftime("%H%M%S"))
(4)函式:
defget_lapseTime(aTime,bTime):
aNum=3600*int(aTime[:2])+60*int(aTime[2:4])+int(aTime[-2:])
bNum=3600*int(bTime[:2])+60*int(bTime[2:4])+int(bTime[-2:])
gapH=(bNum-aNum)//3600
gapM=((bNum-aNum)%3600)//60
gapS=((bNum-aNum)%3600)%60
gapTime="%02d:%02d:%02d"%(gapH,gapM,gapS)
return(gapTime)