If you get the time in seconds, you should multiply it by 1000:
String time = "1369148661"; long timestampLong = Long.parseLong(time)*1000; Date d = new Date(timestampLong); Calendar c = Calendar.getInstance(); c.setTime(d); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int date = c.get(Calendar.DATE); System.out.println(year +"-"+month+"-"+date);
Exit:
2013-4-21
Leaving, because the constant for Calendar.MONTH starts with 0. Therefore, you should display it like this for the user:
System.out.println(year +"-"+(month+1)+"-"+date);
Alexis C.
source share