title: Datetime localization with python/django
body: <p>I am trying to parse an RSS feed. Entries in the feed have date elements like:</p>
  
  <pre><code>&lt;dc:date&gt;2016-09-21T16:00:00+02:00&lt;/dc:date&gt;
  </code></pre>
  
  <p>Using feedparser, I try to do:</p>
  
  <pre><code>published_time = datetime.fromtimestamp(mktime(entry.published_parsed))
  </code></pre>
  
  <p>But the problem is that I seem to be getting the wrong time stored in the database. In this particular case, the datetime is stored as:</p>
  
  <pre><code>2016-09-21 13:00:00
  </code></pre>
  
  <p>... when I would expect 14:00 - the correct UTC time.</p>
  
  <p>I assume the problem is in our django settings, where we have:</p>
  
  <pre><code>TIME_ZONE = 'Europe/Berlin'
  </code></pre>
  
  <p>Because when I switch to:</p>
  
  <pre><code>TIME_ZONE = 'UTC'
  </code></pre>
  
  <p>... the datatime is stored as correct UTC time:</p>
  
  <pre><code>2016-09-21 14:00:00
  </code></pre>
  
  <p>Is there any way to keep the django settings as they are, but to parse and store this datetime correctly, without the django timezone setting affecting it?</p>
  
  <p>EDIT:
  Maybe it's more clear like this...</p>
  
  <pre><code>print entry.published_parsed
  published_time = datetime.fromtimestamp(mktime(entry.published_parsed))
  print published_time
  localized_time = pytz.timezone(settings.TIME_ZONE).localize(published_time, is_dst=None)
  print localized_time
  
  time.struct_time(tm_year=2016, tm_mon=9, tm_mday=21, tm_hour=14, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=265, tm_isdst=0)
  2016-09-21 15:00:00
  2016-09-21 15:00:00+02:00
  </code></pre>