To convert GMT to Mountain Time in Python, you can use the datetime and timezone modules. Here's an example code snippet:
main.py292 chars10 lines
In the above code, we first use the datetime.datetime.now()
function to get the current datetime in GMT timezone. We then use the astimezone()
method to convert this datetime to Mountain Time (US/Mountain timezone). Finally, we print the converted datetime values in both GMT and Mountain Time formats using the strftime()
method.
Note: Make sure to install the pytz module that provides the Olson time zone database for Python to work with timezone conversions as shown in the example above.
gistlibby LogSnag