Django/Python timestamp convert EDT to UTC
Question: I have a Python datetime object and here is the offset and tzname(). As in
Django, the timezone is stored as UTC, I want it store the the tzname
separately, so that I can use that field to reconvert to the actual datetime.

    
    
    >>>from dateutil.parser import parse
    >>>dt = parse('Tue Apr 26 2016 08:32:00 GMT-0400 (EDT)')
    
    >>> dt
    datetime.datetime(2016, 4, 26, 8, 32, tzinfo=tzoffset('EDT', 14400))
    >>> dt.tzinfo
    tzoffset('EDT', 14400)
    >>> dt.tzname()
    'EDT'
    

Question:-

When I store "dt" object in Django it converts it to UTC format.How do I
reconvert the UTC format to EDT format?

I'm using this link as reference but I'm not sure how to create the to_zone
object for 'EDT'. 'UTC' works fine but tz.gettz('EDT') is always None.

    
    
    >>> to_zone=tz.gettz('EDT')
    >>> to_zone
    >>> to_zone=tz.gettz('UTC')
    >>> to_zone
    tzfile('/usr/share/zoneinfo/UTC')
    

[Python - Convert UTC datetime string to local
datetime](http://stackoverflow.com/questions/4770297/python-convert-utc-
datetime-string-to-local-datetime)


Answer: The datetime package has a method "astimezone":

[datetime.astimezone](https://docs.python.org/2/library/datetime.html#datetime.datetime.astimezone)

So

    
    
    tzone = tz.gettz('EDT')
    newdate = olddate.astimezone(tzone)
    

