To convert
Date
to String
in Java, use SimpleDateFormat
.Here's how you do it:
java.util.Date date = new java.util.Date(122, java.util.Calendar.APRIL, 15);
String stringFromDate = new java.text.SimpleDateFormat("yyyy-MM-dd").format(date);
System.out.println(stringFromDate); // 2022-04-15