# 模拟特价商品销售倒计时提示 import datetime # 引入datetime模块 import time # 引入time模块
AScheduledTime = datetime.datetime(2023, 1, 21, 0, 0, 0) # 设置预定时间 Anow =
datetime.datetime.today() # 获取现在的时间 ADifference = AScheduledTime - Anow #
存储两个时间的时间,差精确到毫秒 Asec = ADifference.seconds # 距离预定时间还有多少秒 while (Asec): while
(1): ScheduledTime = datetime.datetime(2023, 1, 21, 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
运行结果:

 

技术
今日推荐
PPT
阅读数 126
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信