Hi all! Just ran into the task of working with time in a different time zone. I had to figure out the solution, so I’m sharing it – it might come in handy for someone 🙂
To solve the issue of working with time in a different time zone, we need the pytz library – you can install it, for example like this:
pip install pytz (however, I talked about installing libraries in more detail here)
After that, our code looks like this:
from pytz import timezone #Connected the library to work with other time zones ukraine_time = timezone('Europe/Kiev') #Specified the time zone we need ua_time = datetime.now(ukraine_time) #Got a variable containing the time in the desired time zone print('Ukraine time:', ua_time) #Displayed this time to screen :)
Thank you for your attention! As always, if you have any questions, write to the mail or Telegram.