Python实现简单倒计时

分享
开发者 2024-10-5 21:58:30 107 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
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-11-22 01:28, Processed in 0.165561 second(s), 33 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表