I am trying to make some code that creates a clock using the user's local time with the datetime library.
import datetime as dt
import os
import time
z = dt.datetime.now()
def local_time():
def time_check(t):
if t < 10:
t = "0{}".format(t)
else:
t = t
return t
p = dt.datetime.now()
hour = p.hour
minute = p.minute
second = p.second
hour = time_check(hour)
minute = time_check(minute)
second = time_check(second)
local_time = '{}:{}:{}'.format(hour, minute, second)
return local_time
time_zone = z.timezone()
for i in range(999999999999999999999):
print("Time: {} {}".format(local_time(), time_zone))
time.sleep(1)
os.system("cls")
What I am doing is gathering the hour, minute, and second of the local time, and constantly updating it in the terminal, and deleting the previous time. This works fine, but I am also trying to display the timezone of the user, and I am having a hard time trying to find a way to do it. Does anyone know a way? Thanks.