I tried to search the forum for this, but it keeps giving me a "high traffic at this time" failure.
I want to convert a UTC time into 6 other timezones. I installed PIP3.2 and used that to install pytz, but the system wouldnt recognize that pytz was installed. So I used easy_install and that seems to have worked, or at least my python script doesnt fail now.
My shell is set to America/Phoenix and my clock script will show my local time if I run it without any pytz nonsense. I can create a UTC time and get that working fine, but when I try to take that object and translate it to any other timezone, the script just freezes.
The above works, or at least it gives me 3 UTC's. What do I need to change to get MST/PST on the last two? I have tried all kinds of things from Google (astimezone, pytz.timezone, etc) and it's all crap. Everything I have tried just causes the script to hang after it prints the first UTC.
Code: Select all
#!/usr/bin/python import time import datetime from pytz import timezone import pytz while(True): utc_now = pytz.utc.localize(datetime.datetime.utcnow()) hour = utc_now.hour minute = utc_now.minute second = utc_now.second print('UTC:', utc_now) mst_now = pytz.utc.localize(datetime.datetime.utcnow()) hour = mst_now.hour minute = mst_now.minute second = mst_now.second print('MST:', mst_now) pst_now = pytz.utc.localize(datetime.datetime.utcnow()) hour = pst_now.hour minute = pst_now.minute second = pst_now.second print('PST:', pst_now)