title: Getting the correct timezone offset in Python using local timezone
body: <p>Ok let me first start by saying my timezone is CET/CEST. The exact moment it changes from CEST to CET (back from DST, which is GMT+2, to normal, which GMT+1, thus) is always the last Sunday of October at 3AM. In 2010 this was 31 October 3AM.</p>
  
  <p>Now note the following:</p>
  
  <pre><code>&gt;&gt;&gt; import datetime
  &gt;&gt;&gt; import pytz.reference
  &gt;&gt;&gt; local_tnz = pytz.reference.LocalTimezone()
  &gt;&gt;&gt; local_tnz.utcoffset(datetime.datetime(2010, 10, 31, 2, 12, 30))
  datetime.timedelta(0, 3600)
  </code></pre>
  
  <p>This is wrong as explained above.</p>
  
  <pre><code>&gt;&gt;&gt; local_tnz.utcoffset(datetime.datetime(2010, 10, 30, 2, 12, 30))
  datetime.timedelta(0, 7200)
  &gt;&gt;&gt; local_tnz.utcoffset(datetime.datetime(2010, 10, 31, 2, 12, 30))
  datetime.timedelta(0, 7200)
  </code></pre>
  
  <p>Now it is suddenly correct :/</p>
  
  <p>I know there are several questions about this already, but the solution given is always "use localize", but my problem here is that the LocalTimezone does not provide that method.</p>
  
  <p>In fact, I have several timestamps in milliseconds of which I need the utcoffset of the local timezone (not just mine, but of anyone using the program). One of these is  1288483950000 or Sun Oct 31 2010 02:12:30 GMT+0200 (CEST) in my timezone.</p>
  
  <p>Currently I do the following to get the datetime object:</p>
  
  <pre><code>datetime.datetime.fromtimestamp(int(int(millis)/1E3)) 
  </code></pre>
  
  <p>and this to get the utcoffset in minutes:</p>
  
  <pre><code>-int(local_tnz.utcoffset(date).total_seconds()/60)
  </code></pre>
  
  <p>which, unfortunately, is wrong in many occasions :(.</p>
  
  <p>Any ideas?</p>
  
  <p>Note: I'm using python3.2.4, not that it should matter in this case.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Found the solution thanks to @JamesHolderness:</p>
  
  <pre><code>def datetimeFromMillis(millis):
      return pytz.utc.localize(datetime.datetime.utcfromtimestamp(int(int(millis)/1E3)))
  
  def getTimezoneOffset(date):
      return -int(date.astimezone(local_tz).utcoffset().total_seconds()/60)
  </code></pre>
  
  <p>With local_tz equal to tzlocal.get_localzone() from the tzlocal module.</p>