To convert GMT to Australian Central Time (ACT) in python, you first need to create a datetime object for the given time in GMT timezone. Then, you can convert this datetime object to the ACT timezone using the astimezone()
method.
Here's an example code snippet to convert GMT to ACT in python:
main.py529 chars20 lines
In this example, we first import datetime and pytz libraries. We define the UTC timezone object using pytz.UTC
, and the ACT timezone object using pytz.timezone('Australia/Adelaide')
.
Next, we define the datetime object for the given time in GMT timezone using datetime.strptime()
. We then localize the datetime object to UTC timezone using utc.localize()
.
Finally, we convert the datetime object to ACT timezone using astimezone()
. We print the GMT and ACT time using print()
function.
Note that you may need to change the ACT timezone based on the location within Australia as it follows various time zones.
gistlibby LogSnag