Python 2.7 - Trying to work convert UTC string to local time taking into account DST
Question: I have a UTC time string like so

    
    
    supplied_datetime = 20160711230000 -0500
    

This is the format

    
    
    yyyyMMddhhmmss +/-hhmm
    

Now if I take that offset (-5hrs) from the original time it should read

    
    
    supplied_datetime = 20160711180000
    

The next part is that I need to correct based on the local time making sure to
account for any dst times.

So lets say i'm in the UK which is UTC 0000 but we are in DST +0100, then the
time that ultimately gets displayed to the user will be

    
    
    supplied_datetime = 20160711190000
    

So the formula is `supplied_datetime - (supplied_utc_offset +
local_utc_offset)`

This is as far as I have got before asking here.

    
    
    local_utc_offset = calendar.timegm(time.localtime()) - calendar.timegm(time.gmtime(time.mktime(time.localtime())))
    
    supplied_utc_offset = parse(programme.get('start')[:20])
    


Answer: If the format of your date time strings are always consistent, you can
manually obtain the local datetime given the utc datetime.

`time.timezone` gives local offset in seconds.

Then you just need to parse the datetime string and add it with local offset
in hours as well as the offset in the datetime string:

    
    
    from datetime import datetime
    import time
    dst = time.localtime().tm_isdst # daylight saving
    local_offset = (dst-(time.timezone / 3600))  * 10000  # Local offset in hours format
    strtime = '20160711230000 -0500'  # The original datetime string
    dtstr, offset = strtime[:-6], strtime[-5:]  # separate the offset from the datetime string
    utc_dt = datetime.strptime(dtstr, '%Y%m%d%H%M%S')
    local_dtstr = str(int(dtstr) + int(offset) * 100 + local_offset)  # get local time string
    local_dt = datetime.strptime(local_dtstr, '%Y%m%d%H%M%S')
    
    In [37]: utc_dt
    Out[37]: datetime.datetime(2016, 7, 11, 23, 0)
    
    In [38]: local_dt
    Out[38]: datetime.datetime(2016, 7, 11, 19, 0)
    

