Python ProgrammingPython Programming

Get current date time in MST, EST, UTC, GMT and HST

The following code snippet illustrates use of pytz and datetime to display current date and time in various MST, EST, UTC, GMT and HST
##
# Python's program to get current time MST EST UTC GMT HST

from datetime import datetime
from pytz import timezone

mst = timezone('MST')
print("Time in MST:", datetime.now(mst))

est = timezone('EST')
print("Time in EST:", datetime.now(est))

utc = timezone('UTC')
print("Time in UTC:", datetime.now(utc))

gmt = timezone('GMT')
print("Time in GMT:", datetime.now(gmt))

hst = timezone('HST')
print("Time in HST:", datetime.now(hst))

Sample output of above program.
C:\programs\time>pep8 --first example6.py

C:\programs\time>python example6.py
Time in MST: 2017-01-19 06:06:14.495605-07:00
Time in EST: 2017-01-19 08:06:14.496606-05:00
Time in UTC: 2017-01-19 13:06:14.496606+00:00
Time in GMT: 2017-01-19 13:06:14.496606+00:00
Time in HST: 2017-01-19 03:06:14.497606-10:00

C:\programs\time>