【转】python 输入一个时间,获取这个时间的下一秒

原文:/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

 

你可能感兴趣的