//Timestamp to HH:mm:ss format
Long Timestamp = 1633304782;
Date timeD = new Date(Timestamp * 1000);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String Time = sdf.format(timeD);
//RESULT this code convert 1633304782 to 05:46:33
String timestampToDate(long timestamp, String pattern)
{
Date timeD = new Date(timestamp);
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(timeD);
}
//You can use this for both date or time.
// long timestamp = System.currentTimeMillis();
// eg: for date use it like this:
//timestampToDate(timestamp, "dd MMM, yyyy");
// eg: for time use it like this:
//timestampToDate(timestamp, "hh:mm a");
// eg: for both:
//timestampToDate(timestamp, "dd MMM, yyyy - hh:mm a");
All you need to do is change the string within the java.text.SimpleDateFormat constructor to: "MM-dd-yyyy HH:mm:ss".
Just use the appropriate letters to build the above string to match your input date.