Assume that you fetch the date from database and pass it to the below method:
public String formatDate(Date date){
SimpleDateFormat ff = new SimpleDateFormat("yyyy-MM-dd");
return ff.format(date);
}
EDIT : based on input from Basil, you could try Android Desugaring to make use of Java 8+ functionality without the need of minimum API level. This would allow the use of LocalDate
instead of the old java.util.Date
class.
Using LocalDate
you could parse a string to date as:
public LocalDate getDate(String dateString) {
return LocalDate.parse(dateString);
}