title: Python 3: timestamp to datetime: where does this additional hour come from?
body: <p>I'm using the following functions:</p>
  
  <pre><code># The epoch used in the datetime API.
  EPOCH = datetime.datetime.fromtimestamp(0)
  
  def timedelta_to_seconds(delta):
      seconds = (delta.microseconds * 1e6) + delta.seconds + (delta.days * 86400)
      seconds = abs(seconds)
  
      return seconds
  
  def datetime_to_timestamp(date, epoch=EPOCH):
      # Ensure we deal with `datetime`s.
      date = datetime.datetime.fromordinal(date.toordinal())
      epoch = datetime.datetime.fromordinal(epoch.toordinal())
  
      timedelta = date - epoch
      timestamp = timedelta_to_seconds(timedelta)
  
      return timestamp
  
  def timestamp_to_datetime(timestamp, epoch=EPOCH):
      # Ensure we deal with a `datetime`.
      epoch = datetime.datetime.fromordinal(epoch.toordinal())
  
      epoch_difference = timedelta_to_seconds(epoch - EPOCH)
      adjusted_timestamp = timestamp - epoch_difference
  
      date = datetime.datetime.fromtimestamp(adjusted_timestamp)
  
      return date
  </code></pre>
  
  <p>And using them with the passed code:</p>
  
  <pre><code>twenty = datetime.datetime(2010, 4, 4)
  
  print(twenty)
  print(datetime_to_timestamp(twenty))
  print(timestamp_to_datetime(datetime_to_timestamp(twenty)))
  </code></pre>
  
  <p>And getting the following results:</p>
  
  <pre><code>2010-04-04 00:00:00
  1270339200.0
  2010-04-04 01:00:00
  </code></pre>
  
  <p>For some reason, I'm getting an <em>additional</em> hour added in the last call, despite my code having, as far as I can see, no flaws.</p>
  
  <p>Where is this additional hour coming from?</p>