+ 3

How can I get Python to countdown to a set date in the future?

3rd Oct 2018, 7:29 PM
Brandon Shaw
2 odpowiedzi
+ 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
3rd Oct 2018, 8:25 PM
strawdog
strawdog - avatar
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..
23rd Jul 2021, 4:48 PM
Derek Daniels