Let's say I have a date like Fri Jul 16 12:04:35 EAT 2021
I want to change it to 16-JUL-2021. How do I go about it?
Let's say I have a date like Fri Jul 16 12:04:35 EAT 2021
I want to change it to 16-JUL-2021. How do I go about it?
ZonedDateTime zdt = ZonedDateTime.parse("Fri Jul 16 12:04:35 EAT 2021", DateTimeFormatter.ofPattern("EEE MMM d HH:mm:ss z yyyy
"));
String newDate = zdt.format(DateTimeFormatter.ofPattern("dd-MMM-yyyy")).toUpperCase();
You can use SimpleDateFormat:
import java.text.SimpleDateFormat;
//...
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd-LLL-yyyy");
String text = sdf.format(date);
String startDateInput = "Fri Jul 16 12:04:35 EAT 2021";
String date = startDateInput.substring(8, 10) + "-" +
startDateInput.substring(4, 7) + "-"
+ startDateInput.substring(startDateInput.length() - 4);