Python time accumulates more than 24 hours and continues to accumulate

Source: Internet
Author: User

Recently, I've been working on a tool that asks for the time it takes to run the program, so I made a timer.

Found on the internet a lot of discoveries are 24-hour system, more than 24 hours will be back 0

And then, based on the 24-hour system, I modified a constant-time

If you want to display more than 24 hours in the day, you can modify the accumulated part of the Code

#-*-coding:utf-8-*-ImportSYS fromPyqt5.qtwidgetsImport* fromPyqt5.qtcoreImport* fromPyqt5.qtcoreImportQtimer, QtimeclassFirstwindow (qwidget): Close_signal=pyqtsignal ()def __init__(Self, parent=None): Super (Firstwindow, self).__init__(parent) self.resize (100, 100) Self.timer= Qtimer ()#Self.timeclock =qtime () self.h24=0 Self.istimestart=False Self.label=Qlabel (self) self.label.setText ('0:00:00')        if  notSelf.isTimeStart:self.timeClock.setHMS (0, 0, 0) self.timer.start (1000)#start timer, the timer object emits a timeout signal every secondSelf.istimestart =True self.timer.timeout.connect (self.addtime)defAddtime (self):#chronograph time is increased by one second and displayed on QlableSelf.timeclock = self.timeClock.addMSecs (1000)#time increases by one secondTime = self.timeClock.toString ("Hh:mm:ss")        ifTime = ="00:00:00": Self.h24+ = 24h= Int (Time.split (":") [0]) +self.h24 M= Time.split (":") [1] s= Time.split (":") [2] New_time="%d:%s:%s"%(H, M, s) self.label.setText (new_time)#Label Display Timeif __name__=="__main__": App=qapplication (SYS.ARGV) ex=Firstwindow () ex.show () Sys.exit (App.exec_ ())

Python time accumulates more than 24 hours and continues to accumulate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.