Convert time from one timezone to another one
We can convert a date-time from one timezone to another using pytz module
Python: 3.0    Anurag Rana    13 Jul 2021   1
Login to upvote
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from datetime import datetime
import pytz

timezone_tokyo = pytz.timezone('Asia/Tokyo')
tokyo_datetime_obj = datetime.now(timezone_tokyo)

timezone_istanbul = pytz.timezone('Europe/Istanbul')
istanbul_datetime_obj = tokyo_datetime_obj.astimezone(timezone_istanbul)

print('Asia/Tokyo:', tokyo_datetime_obj.time()) # ('Asia/Tokyo:', datetime.time(23, 4, 42, 684766))
print('Europe/Istanbul:', istanbul_datetime_obj.time()) # ('Europe/Istanbul:', datetime.time(17, 4, 42, 684766))
Copy | Download as: .py file   PNG
Share on: FB   Twitter   LinkedIn   WA
©2021 - code108labs   Contributors   Hosted on DigitalOcean   Partner website: pythoncircle.com