xxxxxxxxxx
// time is of format yyyy-MM-dd HH:mm:ss
fun formatTimeToTimeString(time: String): String {
val dtf: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
val date :LocalDate = LocalDate.parse(time,dtf)
return " ${date.dayOfMonth} ${date.month} ${date.year}"
// out put will be eg: 10 Jan 2022
}
xxxxxxxxxx
LocalDate date = LocalDate.now(); //get current date
System.out.println(date);
xxxxxxxxxx
public LocalDate convertToLocalDateViaInstant(Date dateToConvert) {
return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}