通过代码根据开始时间和现在时间,以及剩余量实现展示剩余时间倒计时
4条回答 默认 最新
- CSDN专家-sinJack 2023-03-26 08:41关注
import datetime import time AScheduledTime = datetime.datetime(2020, 6, 18, 0, 0, 0) Anow = datetime.datetime.today() # 获取现在的时间 ADifference = AScheduledTime - Anow # 存储两个时间的时间,差精确到毫秒 Asec = ADifference.seconds # 距离预定时间还有多少秒 while (Asec): while (1): ScheduledTime = datetime.datetime(2020, 6, 18, 0, 0, 0) # 设置预定时间 now = datetime.datetime.today() # 获取现在的时间 Difference = ScheduledTime - now # 存储两个时间的时间,差精确到毫秒 day = Difference.days # 距离预定时间还有多少天 sec = Difference.seconds # 距离预定时间还有多少秒 hour = int(sec / 60 / 60) # 距离预定时间还有多少小时,并换算为int型 minute = int(sec / 60 % 60) # 距离预定时间还有多少分钟,并换算为int型 second = sec % 60 # 距离预定时间还有多少秒,并换算为int型 print('距离结束:' + str(day) + '天 ' + str(hour) + '时 ' + str(minute) + '分 ' + str(second) + '秒') time.sleep(1) Asec -= 1
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报