数字转时分秒-Python

    def num2HourMinSec(num):
        m, s = divmod(num, 60)
        h, m = divmod(m, 60)
        timestr = "%02d:%02d:%02d" % (h, m, s)
        return timestr
import time
for i in range(121):   #120秒倒计时,这里121可以是变量,替换称所需要的数据就可用制作成任意时间的倒计时了,我一般用这个倒计时做自动化运行的一个脚本
    seconds = 120 - i
    time.sleep(1)
    m, s = divmod(seconds, 60)
    h, m = divmod(m, 60)
    print ("
剩余%02d时%02d分%02d秒" % (h, m, s),end="")

转载仅为学习,不会商用。
欢迎转载原创,附文链接。
原文地址:https://www.cnblogs.com/xdd1997/p/13512324.html