+ 3
How can I get Python to countdown to a set date in the future?
2 Respostas
+ 1
This will give you remaining days/hours/minutes/seconds to a given date(Nov 1 2018 13:33) from now:
=====
from datetime import datetime
futuredate = datetime.strptime('Nov 1 2018 13:33', '%b %d %Y %H:%M')
nowdate = datetime.now()
count = int((futuredate-nowdate).total_seconds())
days = count//86400
hours = (count-days*86400)//3600
minutes = (count-days*86400-hours*3600)//60
seconds = count-days*86400-hours*3600-minutes*60
print("{} days {} hours {} minutes {} seconds left".format(days, hours, minutes, seconds))
====
You can wrap it into a loop if you want
0
What if the future day is a variable say the day is 7days from the day the user triggers it and this will be different for different users..