title: Android unix timestamp - Converter
body: <p>In my android app I'm creating a timestamp this way:</p>
  
  <pre><code>final BackupInfo backupInfo = new BackupInfo(description, System.currentTimeMillis(), backupContacts.size());
  </code></pre>
  
  <p>eg, using <code>System.currentTimeMillis()</code></p>
  
  <p>Now I convert it back to date format using:</p>
  
  <pre><code>public static String getDate(long time) 
  {
      Calendar cal = Calendar.getInstance();
      cal.setTimeInMillis(time);
      String date = DateFormat.format("dd-MM-yyyy HH:mm:ss", cal).toString();
      return date;
  }
  </code></pre>
  
  <p>And it works fine.</p>
  
  <p>But now I'm receiving a timestamp from a server and the date String I receive from <code>getDate</code> is not the correct date.</p>
  
  <p><strong>Practical case:</strong></p>
  
  <p>My app generates this timestamp: <code>1403022230766</code></p>
  
  <p><code>getDate</code> returns this date: <code>17-06-2014 05:23:50</code> which is correct to my eyes.</p>
  
  <p>Now the problem comes in, I get this timestamp from the server: <code>1403022360</code></p>
  
  <p><code>getdate</code> returns this date: <code>16-01-1970 18:43:42</code> which is totally wrong, it should be close to the timestamp generated by my app.</p>
  
  <p>The timestamp returned by the server is 3 digits less in size. But if I go to an online converter, like <a href="http://www.epochconverter.com/" rel="nofollow">this one</a> and I put <code>1403022360</code> (the TS generated by the server) I get a correct date.</p>
  
  <p>Can anyone explain me why this difference and what am I doing wrong in my <code>getDate</code> method that I can't decode the timestamp received from the server?</p>