title: How to convert an integer timestamp back to UTC datetime?
body: <p>When syncing between iOS and my Python GAE backend, I would like to utilise the timestamp for a clean solution.</p>
  
  <p>According to my research this is the best way to create a <a href="https://stackoverflow.com/a/2775982/92153">reliable timestamp</a>:</p>
  
  <pre><code>calendar.timegm((datetime.datetime.now()).utctimetuple())
  </code></pre>
  
  <p>where I get an integer like this: <code>1382375236</code></p>
  
  <p>When on the backend, I would like to additionally save the <code>last_updated</code> datetime derived from the timestamp.  That is human readable and good for a quick check.</p>
  
  <pre><code>def before_put(self):
      self.last_updated = datetime.utcfromtimestamp(self.timestamp)
  </code></pre>
  
  <p>However this fails with an error:</p>
  
  <pre><code>TypeError: a float is required
  </code></pre>
  
  <p>What is the best way of solving this in an accurate way?</p>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>I also found this suggestion <a href="https://stackoverflow.com/a/9744811/92153">here:</a>
  The solution would be dividing it by <code>1e3</code>.</p>
  
  <p>In my case this gives me a strange date:</p>
  
  <pre><code>&gt;&gt;&gt; datetime.datetime.utcfromtimestamp(1382375236 / 1e3)
  datetime.datetime(1970, 1, 16, 23, 59, 35, 236000)
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>The entire model is:</p>
  
  <pre><code>class Record(ndb.Model):
      user = ndb.KeyProperty(kind=User)
      record_date = ndb.DateProperty(required=True)
      rating = ndb.IntegerProperty(required=True)
      notes = ndb.TextProperty()
      last_updated = ndb.DateTimeProperty(required=True)
      timestamp = ndb.IntegerProperty(required=True)
  
      def __repr__(self):
          return '&lt;record_date %r&gt;' % self.record_date
  
      def before_put(self):
          self.last_updated = datetime.utcfromtimestamp(self.timestamp)
  
      def after_put(self):
          pass
  
      def put(self, **kwargs):
          self.before_put()
          super(Record, self).put(**kwargs)
          self.after_put()
  </code></pre>