0

i'm trying to convert whatever the user select time timezone it should convert into uk timezone. I've found a package in python called "pytz" but the list of timezones are different from my windows local system timezones. I've searched for micorsoft default system timezones and trying to convert them in uk timezones

please click the below link for microsoft default system timezone details.

https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-time-zones?view=windows-11

windows system timezones

for example instead passing 'Asia/Kolkata' to my "get_uk_time" function i'm trying to pass windows local system timezone as "Chennai, Kolkata, Mumbai, New Delhi" or India Standard Time or IN. similar way for other timezones which are available in the microsoft link above

i've tried below approch but unable to find how to convert above local windows system timezones.

from datetime import datetime
from pytz import timezone

def get_uk_time(time_zone):
    try:
        country_tz = timezone(time_zone)
        format = "%Y, %m, %d, %H, %M, %S"
        time_now = datetime.now(timezone(time_zone))
        format_time = time_now.strftime(format)
        london_tz = timezone('Europe/London')

        local_time = country_tz.localize(datetime.strptime(format_time, format))
        convert_to_london_time = local_time.astimezone(london_tz)
        uk_time = convert_to_london_time.strftime('%H:%M')
        return uk_time
    except:
        print('unable to find the timezone')

my_json = {'timezone': 'Asia/Kolkata'}
time_zone = my_json['timezone']
time_in_london = get_uk_time(time_zone)
print(time_in_london)

please help.

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
sruthi
  • 163
  • 9
  • You are trying to get the current time in the UK? or how would you like for it to convert? Currently it prints out the local time in the UK – Andrew Ryan Feb 05 '22 at 02:23
  • @AndrewRyan thanks for your reply. currently i'm passing ''Asia/Kolkata'' to my "get_uk_time" function instead i'm trying to pass windows local system timezone "Chennai, Kolkata, Mumbai, New Delhi" or India Standard Time or IN. similar way for other timezones which are available in the microsoft link i provided – sruthi Feb 05 '22 at 02:31
  • 1
    https://stackoverflow.com/questions/16156597/how-can-i-convert-windows-timezones-to-timezones-pytz-understands – Andrew Ryan Feb 05 '22 at 02:43

0 Answers0