python倒计时源码
import datetime day20 = datetime.datetime.strptime('2021-12-20 0:0:0','%Y-%m-%d %H:%M:%S') # 设置未来时间 now = datetime.datetime.today() delta = day20 - now # delta存储两个时间的时间,差精确到毫秒 day = delta.days # 获取两个时间之间的天数 hour = int( delta.seconds / 60 / 60 ) # 使用int函数把小时取整 minutes = int( ( delta.seconds - hour * 60 * 60 ) / 60 ) # 使用int函数把分钟取整 seconds = delta.seconds - hour * 60 * 60 - minutes * 60 # 使用int函数把秒取整 print('\033[31;43m距离结束:\033[43m' + '\033[34;43m'+str(day)+'\033[43m'+'\033[31;43m天\033[43m'+'\033[34;43m'+str(hour)+'\033[43m'+'\033[31;43m小时\033[43m'+'\033[34;43m'+str(minutes)+'\033[43m'+'\033[31;43m分钟\033[43m'+'\033[34;43m'+str(seconds)+'\033[43m'+'\033[31;43m秒\033[0m')
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。