convert gmt to hawaii time in python

To convert GMT (Greenwich Mean Time) to Hawaii Time in Python, first, we need to import the datetime and timezone modules. We can then create a datetime object with a timezone of GMT using the datetime.datetime and datetime.timezone classes. Finally, we can convert the datetime object to Hawaii Time by using the astimezone() method with the timezone of Hawaii.

Here's an example code snippet:

main.py
import datetime
import pytz

# create a datetime object with timezone of GMT
gmt_time = datetime.datetime.now(datetime.timezone.utc)

# convert GMT to Hawaii Time
hawaii_tz = pytz.timezone('US/Hawaii')
hawaii_time = gmt_time.astimezone(hawaii_tz)

# print the Hawaii Time in ISO format
print(hawaii_time.isoformat())
317 chars
13 lines

This code snippet will output the current time in Hawaii in ISO format. You can replace the now() method with any other datetime object to convert a specific GMT time to Hawaii Time.

gistlibby LogSnag