【轉】python 輸入一個時間,獲取這個時間的下一秒


原文:https://blog.csdn.net/l_d_56/article/details/84832198

輸入一個時間,獲取這個時間的下一秒

PS:下面代碼使用於 python 2.7

time1 = raw_input("輸入一個時間[HH:MM:SS]:")
time1List = time1.split(":")
time1List = [int(x) for x in time1List]

shi = time1List[0]
fen = time1List[1]
miao = time1List[2]

if miao == 59:
    miao = 0
    fen += 1
    if fen == 60:
        fen = 0
        shi += 1
        if shi == 24:
            shi = 0
else:
    miao += 1
print '輸出下一秒的時間為:%02d:%02d:%02d' % (shi, fen, miao)

輸出:

輸入一個時間[HH:MM:SS]:11:03:00
輸出下一秒的時間為:11:03:01

Process finished with exit code 0

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM