Home > OS >  Did timezone() get any changes recently? Some of my code that used to work fine doesn't work an
Did timezone() get any changes recently? Some of my code that used to work fine doesn't work an

Time:01-09

I've written some code a while back (around April of 2021), and as I recall, the code worked exactly how I had wanted it. If you were wondering, the code is supposed to gather the hour, minute, second, along with the date and timezone, and display it every second.

from pytz import timezone
import datetime as dt
import os
import time

def local_time():

    def time_check(t):
        if t < 10:
            t = "0{}".format(t)
            
        return t

    p = dt.datetime.now()

    hour = time_check(p.hour)
    minute = time_check(p.minute)
    second = time_check(p.second)

    local_time = '{}:{}:{}'.format(hour, minute, second)
    return local_time

for i in range(999999999999999999999):
    time_zone = timezone(zone=None)
    print("Time: {} {}".format(local_time(), time_zone))
    time.sleep(1)
    os.system("cls")

The area that I've been getting errors at is timezone(zone=None) in line 33. Is there a change with this function or am I missing something?

CodePudding user response:

You can do something like this instead

from datetime import datetime
import time
while True:
    print(datetime.now().astimezone().strftime("Time: %H:%M:%S %Z"))
    time.sleep(1)
  •  Tags:  
  • Related