i've a python dictionary. in the below python function i'm passing timezone, country and time. I'm trying to convert whatever the timezone or time i've passed it should return UK time. I'm new to python. i've tried my best to get the solution but unable to get the output.
from datetime import datetime import pytz
def convert_to_uk_time(timezone, country, time):
naive_time = datetime.strptime(time, '%H:%M')
tz = pytz.timezone(timezone)
tz_time = tz.localize(naive_time)
london_tz = pytz.timezone('Europe/London')
london_time = tz_time.astimezone(london_tz)
return london_time
my_json= {'timezone': 'Asia/Kolkata', 'country':'India', 'time': '10:25 PM'}
timezone = my_json['timezone']
country = my_json['country']
time = my_json['time']
res = convert_to_uk_time(timezone, country , time)
print(res)
I'm expecting output something like this:
4:55 PM
please guide be with the better solution.