美文网首页
Python实现简单倒计时

Python实现简单倒计时

作者: 吕建雄 | 来源:发表于2023-02-13 17:19 被阅读0次

    # -*- coding : UTF-8 _*_

    # 开发人员: jianxionglyu

    # 开发时间: 2023/2/14 16:57

    # 文件名称: TimeShow.py

    # 开发工具: PyCharm

    import datetime

    import time

    AScheduledTime = datetime.datetime(2023, 6, 18, 0, 0, 0)    #设置预定时间

    Anow = datetime.datetime.today()                                                #获取现在的时间

    ADifference = AScheduledTime - Anow                          #存储两个时间的时差,差精确到毫秒

    Asec = ADifference.seconds                                            #距离预定时间还有多少秒

    while (Asec):

        while (1):

            ScheduleTime = datetime.datetime(2023, 6, 18, 0, 0, 0)

            now = datetime.datetime.today()

            Difference = ScheduleTime - now

            day = Difference.days

            sec = Difference.seconds

            hour =int(sec /60 /60)

            minute =int(sec /60 %60)

            second = sec %60

            print('距离618还有:' +str(day) +'天天' +str(hour) +'时' +str(minute) +'分' +str(second) +'秒')

            time.sleep(1)

            Asec -=1

    相关文章

      网友评论

          本文标题:Python实现简单倒计时

          本文链接:https://www.haomeiwen.com/subject/uzqskdtx.html