Skip to content

Instantly share code, notes, and snippets.

@shimo164
Created March 18, 2019 10:17
Show Gist options
  • Save shimo164/9355640e539d8340b98eaa0b3aaabd40 to your computer and use it in GitHub Desktop.
Save shimo164/9355640e539d8340b98eaa0b3aaabd40 to your computer and use it in GitHub Desktop.
Timer: wait until set_time
import datetime
import time
set_time = datetime.datetime(2019, 12, 31, 19, 0)
now_time = datetime.datetime.now()
delta = set_time - now_time
sec_in_day = (delta.total_seconds() - delta.days*24*60*60)
hours = int(sec_in_day // (60*60))
minutes = int((sec_in_day - hours*(60*60)) // 60)
seconds = int(sec_in_day - minutes*60 - hours*60*60)
if delta.total_seconds() < 0:
print("worng set_time")
else:
print('Timer:', set_time)
print(f'wait time: {delta.days}days {hours}h {minutes}m {seconds}s')
time.sleep(delta.total_seconds())
print("wryyyy!!!") # script start!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment