convert australian central standard time to gmt in python

You can use the datetime module to convert Australian Central Standard Time (ACST) to Greenwich Mean Time (GMT). The first step is to create a datetime object for the ACST time, specifying the timezone as 'Australia/Adelaide'. Then, you can use the astimezone() method to convert the timezone to GMT.

Here's an example code snippet:

main.py
from datetime import datetime
from pytz import timezone

# create datetime object for ACST time
acst_time = datetime.now(timezone('Australia/Adelaide'))

# convert to GMT
gmt_time = acst_time.astimezone(timezone('GMT'))

print('ACST time:', acst_time)
print('GMT time:', gmt_time)
281 chars
12 lines

In this example, we first import datetime and the timezone() function from the pytz module. We create a datetime object for the current time in the ACST timezone using datetime.now() and specifying the timezone. Finally, we convert to GMT using astimezone() and print both times.

gistlibby LogSnag