Update: I found a solution to this question and posted it in the comment.
I'm new to Python. I've been searching for resources to guide me how to display local time in a different timezone (in UTC), but all I found was converting based on current time.
For example, my local timezone is 'Asia_Singapore'. How to I get the my local time in UTC - 1 which is 7:00 AM?
If it helps, I'm trying to do something like this tool: https://www.timeanddate.com/worldclock/meetingtime.html?iso=20230106&p1=145&p2=108&p3=56&p4=304&p5=179&p6=220
One of the code snippet I tried was from this page:
from datetime import datetime
import pytz
fmt = '%Y-%m-%d %H:%M:%S %Z%z'
# Print current time
print(datetime.now().strftime(fmt))
# Show current time in Berlin timezone
tz_berlin = pytz.timezone('Europe/Berlin')
local = tz_berlin.localize(datetime.now())
print("Berlin Time::", local.strftime(fmt))
# Show UTC + 2 time in local timezone
tz_sin = pytz.timezone('Asia/Singapore')
dt = datetime(2023, 1, 6, 2, 0, 0)
local = tz_sin.localize(dt)
print("Singapore Time in UTC + 2::", local.strftime(fmt))
Output:
2023-01-06 10:27:44
Berlin Time:: 2023-01-06 10:27:44 CET+0100
Singapore Time in UTC + 2:: 2023-01-06 02:00:00 +08+0800
What I expected:
2023-01-06 18:27:44
Berlin Time:: 2023-01-06 11:27:44 CET+0100
Singapore Time in UTC + 2:: 2023-01-06 10:00:00 +08+0800
Thank you in advance!