main.py449 chars19 lines
In this code block, we first import the required modules: pytz
and datetime
. We then set the timezone to Alaska using pytz.timezone('America/Anchorage')
.
We get the current time in Alaska using datetime.now(ak_tz)
.
To convert Alaska time to GMT, we set the timezone to GMT using pytz.timezone('GMT')
and use the astimezone()
method to convert the Alaska time to GMT.
Finally, we format the time to display using strftime()
and print the Alaska and GMT times.
gistlibby LogSnag