倒计时(python)

2018-8-1倒计时

from datetime import datetime
import time

def zhuan(t):
if t>9:
return t
else:
return '0'+str(t)

now_time=time.time()
s='2018-8-1'
aid_date=datetime.strptime(s,'%Y-%m-%d')#先转化日期
aid_time=int(time.mktime(aid_date.timetuple()))#转化为时间戳
dao_time=int(aid_time-now_time)#时间差
dao_month=zhuan(dao_time//(60
602430)) dao_days=zhuan(dao_time//(606024)%30) dao_hours=zhuan(dao_time//(6060)%24%30)
dao_minutes=zhuan(dao_time//60%60)
dao_seconds=zhuan(dao_time%60)

print('剩余时间:{0}月{1}天{2}小时{3}分钟{4}秒'.format(dao_month,dao_days,dao_hours,dao_minutes,dao_seconds))

作者:Stobadiouth
来源:CSDN
原文:https://blog.csdn.net/qq_42650983/article/details/81208178

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注