I am trying to parse the date in a specific pattern but every time it is showing date in only format. Here what I am doing. Output is written in comments in front of the line.
String dat = "20-06-2021";
String newFormatLocaleDate = "MMM dd yyyy";
String newFormattedDate = convertToNewFormat(dat,currentFormat,newFormatLocaleDate); //Jun 20 2021
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern(newFormatLocaleDate);
LocalDate parse1 = java.time.LocalDate.parse(newFormattedDate,formatter1); //2021-06-20
System.out.println("Using parse1 Pattern Only "+parse1); //2021-06-20
Date date1 = java.sql.Date.valueOf(parse1);
System.out.println("Using Date Pattern Only "+date1); //2021-06-20
The pattern in which date is required is given and in the string form it giving the correct value but when I am trying to parse it with LocaleDate
it is changing the format for all dates to the above mentioned (yyyy-MM-dd)
format irrespective of the newFormatLocaleDate pattern.
Thanks