I have a problem in displaying the date,I am getting timestamp as 1379487711 but as per this the actual time is 9/18/2013 12:31:51 PM but it displays the time as 17-41-197
current date and time:
private String getDateTime() {
Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
Long time = System.currentTimeMillis();
calendar.setTimeInMillis(time);
//dd=day, MM=month, yyyy=year, hh=hour, mm=minute, ss=second.
String date = DateFormat.format("dd-MM-yyyy hh:mm:ss",calendar).toString();
return date;
}
Note: If your result always returns 1970, try this way :
Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
calender.setTimeInMillis(time * 1000L);
String date = DateFormat.format("dd-MM-yyyy hh:mm:ss", calendar).toString();