Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading