倒计时(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*60*24*30))
dao_days=zhuan(dao_time//(60*60*24)%30)
dao_hours=zhuan(dao_time//(60*60)%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))

猜你喜欢

转载自blog.csdn.net/qq_42650983/article/details/81208178