-
Notifications
You must be signed in to change notification settings - Fork 4
/
new_year_countdown.py
34 lines (26 loc) · 958 Bytes
/
new_year_countdown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from time import sleep
from datetime import datetime
def count_down():
new_year = datetime(datetime.now().year + 1, 1, 1)
today = datetime.now()
day_diff = new_year.day - today.day
if day_diff < 0:
day_diff = 30 + new_year.day - today.day
month_diff = 12 - today.month
total_days = int(day_diff + ((month_diff/2) * 30) + ((month_diff / 2) * 31))
hour_diff = new_year.hour - today.hour
if hour_diff < 0:
hour_diff = (new_year.hour - today.hour) + 23
minute_diff = new_year.minute - today.minute
if minute_diff < 0:
minute_diff = 59 + new_year.minute - today.minute
sec_diff = new_year.second - today.second
if sec_diff < 0:
sec_diff = 59 + (new_year.second - today.second)
return f'{day_diff} Days {hour_diff} Hours {minute_diff} Minutes and {sec_diff} Seconds'
while True:
os.system('clear')
print(count_down())
sleep(1)
os.system('clear')