I am trying to convert GMT time to EST/EDT format in Python.
GMT Format: Wed, 06 Feb 2019 20:47:46 GMT
Required Format: 2019-02-06 15:47:46 EST (when daylight time starts it should be EDT)
I need this without doing any additional pip install. Currently, I am using below code which is giving EST time as : 2019-02-06 15:47:46-05:00
import datetime
from datetime import datetime
from dateutil import tz
enable_date = response["ResponseMetadata"]["HTTPHeaders"]["date"]
print "Enable Date in GMT: {0}".format(enable_date)
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('US/Eastern')
utc = datetime.strptime(enable_date, '%a, %d %b %Y %H:%M:%S GMT')
utc = utc.replace(tzinfo=from_zone)
central = utc.astimezone(to_zone)
print "Enable Date in EST: {0}".format(central)
output:
Enable Date in GMT: Wed, 06 Feb 2019 20:47:46 GMT
Enable Date in EST: 2019-02-06 15:47:46-05:00
desired output:
Enable Date in EST: 2019-02-06 15:47:46 EST
Variable enable_date has value Wed, 06 Feb 2019 20:47:46 GMT