In my android app I'm creating a timestamp this way:
final BackupInfo backupInfo = new BackupInfo(description, System.currentTimeMillis(), backupContacts.size());
eg, using System.currentTimeMillis()
Now I convert it back to date format using:
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;
}
And it works fine.
But now I'm receiving a timestamp from a server and the date String I receive from getDate is not the correct date.
Practical case:
My app generates this timestamp: 1403022230766
getDate returns this date: 17-06-2014 05:23:50 which is correct to my eyes.
Now the problem comes in, I get this timestamp from the server: 1403022360
getdate returns this date: 16-01-1970 18:43:42 which is totally wrong, it should be close to the timestamp generated by my app.
The timestamp returned by the server is 3 digits less in size. But if I go to an online converter, like this one and I put 1403022360 (the TS generated by the server) I get a correct date.
Can anyone explain me why this difference and what am I doing wrong in my getDate method that I can't decode the timestamp received from the server?