DateTimeFormatter
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM d HH:mm:ss yyyy");
System.out.println(LocalDate.parse(str, formatter));
Output:
2018-06-10
You can parse as below with SimpleDateFormat :
public static void main(String[] args) throws IOException, ParseException {
String str = "Sun Jun 10 05:23:03 2018";
DateFormat fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.ENGLISH);
DateFormat targetFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = fmt.parse(str);
System.out.println(date);
System.out.println(targetFormat.format(date));
}
Outputs :
Sun Jun 10 05:23:03 EET 2018
10-06-2018