[Solved] Convert Date in Java [duplicate]


I would use the DateTimeFormatter for this. You can find more information in the docs.
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

However, here an example:

DateTimeFormatter parser = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
LocalDateTime date = LocalDateTime.parse("Sun Apr 01 01:00:00 EEST 2018", parser);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
System.out.println(formatter.format(date)); //01-04-2018 01:00:00

The Locale.US part is required even if you don’t live in the US, otherwise it may not be able to parse Sun to Sunday and Apr to April an so on. Probably it works with Locale.UK to and more but for example it didn’t work for me without because i live in switzerland.

solved Convert Date in Java [duplicate]