kotlin date to string format LocalDate code example
Example 1: format localdate java
LocalDate today = LocalDate.now();
String formattedDate = today.format(DateTimeFormatter.ofPattern("dd-MMM-yy"));
System.out.println(formattedDate);
Example 2: date to string kotlin
private fun Date.dateToString(format: String): String {
val dateFormatter = SimpleDateFormat(format, Locale.getDefault())
return dateFormatter.format(this)
}
val timestampt = Date()
val dateString = timestamp.dateToString("hh:mm a E dd-MMM")