Python Timezone Conversion

preview_player
Показать описание
Python Timezone Conversion
Working in infrastructure or just writing code for applications, you will come across times where you have to work with different times ;)
Well in that case we have a ready made timezone module from python.
We will see a very simple example of how timezone conversion works in Python.

Follow our socials to be updated with our videos:
Рекомендации по теме
Комментарии
Автор

If am given time of certain time zone like 3:45PM (GMT -4), how do I convert it into local time?

thelostman
Автор

Excellent work, thank you! I would like to ask how to convert/change dataframe's index timezone. Output is:

2020-10-01


2020-10-01


2020-10-01


2020-10-01
....
....


Timezone is UTC, I want to change it to UTC+3 and I want it looks like "2020-10-01 03:00, 2020-10-01 03:15" and so on...

ugurpotaker
Автор

import datetime as dt

import pytz

time_st ="13:00"

from_zone = pytz.timezone("Etc/GMT")

to_zone = pytz.timezone('Asia/Kolkata')

time_utc = dt.datetime.strptime(time_st, '%H:%M')

local_utc = from_zone.localize(time_utc, is_dst=True)

new_time = local_utc.astimezone(to_zone)







Output:-

13:00

18:53

Expected output:-

13:00

18:30

Please if anyone can help

theanimeguy