python计算当前输入时间的下一秒

发布时间:2019-08-29 07:40:28编辑:auto阅读(1930)

    '''
    time: 12:00:00 plus 1 second
    time result : 12:00:01
    '''

    t1 = input("pls input the time: ")
    list1 = t1.split(":")
    hour = eval(list1[0])
    minute = eval(list1[1])
    second = eval(list1[2])
    if hour > 24 or minute > 59 or second > 59 :
    print("pls input the right format")
    exit()
    if second < 59 :
    print("%d:%d:%d"%(hour,minute,second + 1))
    else:
    if minute < 59 :
    print("%d:%d:00"%(hour,minute + 1))
    else:
    if hour < 23 :
    print("%d:00:00"%(hour + 1))
    else:
    print("00:00:00")

关键字