I am new to programming and I've been trying to create a python script that will take an input time/date from UTC timezone and provide the same time in Pacific.
The problem with my script is that for some reason, the output is not converting properly to the PST timezone, and I cannot figure out what I am doing wrong.
Was wondering if anyone could give me some tips here, thanks.
import os
import subprocess
import pytz
import keyboard
from datetime import datetime
import time
import parse
import sys
dt_utcnow = datetime.now(tz=pytz.timezone('UTC'))
print( "The current UTC time is:", dt_utcnow.strftime("%m/%d/%Y %I:%M:%S %p"))
dt_pacnow = datetime.now(tz=pytz.timezone('US/Pacific'))
print( "The current Pacific time is:", dt_pacnow.strftime("%m/%d/%Y %I:%M:%S %p"))
dt_utc_input = input('Please input the UTC time to convert to Pacific time (Input as MM/DD/YYYY HH:MM:SS AM/PM):')
unaware_utc = datetime.strptime(dt_utc_input, "%m/%d/%Y %I:%M:%S %p")
aware_utc = unaware_utc.astimezone(tz=pytz.timezone('Universal'))
aware_pac = unaware_utc.astimezone(tz=pytz.timezone('US/Pacific'))
print(aware_pac.strftime("%m/%d/%Y %I:%M:%S %p"))
Here is an example output from the above code
The current UTC time is: 09/30/2019 08:49:01 PM
The current Pacific time is: 09/30/2019 01:49:02 PM
Please input the UTC time to convert to Pacific time (Input as MM/DD/YYYY HH:MM:SS AM/PM):09/30/2019 08:49:01 PM
09/30/2019 06:49:01 PM