I have a string like the following
Fri May 31 2019 05:08:40 GMT-0700 (PDT)
I want to convert this to something like yyyy-MM-dd
.
I tried this.
String date1 = "Fri May 31 2019 05:08:40 GMT-0700 (PDT)";
DateTimeFormatter f = DateTimeFormatter.ofPattern( "E MMM dd HH:mm:ss z uuuu" ).withLocale( Locale.US );
ZonedDateTime zdt = ZonedDateTime.parse( date1 , f );
LocalDate ld = zdt.toLocalDate();
DateTimeFormatter fLocalDate = DateTimeFormatter.ofPattern( "yyyy-MM-dd" );
String output = ld.format( fLocalDate ) ;
I am getting the error:
Exception in thread "main" java.time.format.DateTimeParseException: Text
'Fri May 31 2019 05:08:40 GMT-0700 (PDT)' could not be parsed at index 13
at java.time.format.DateTimeFormatter.parseResolved0(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.ZonedDateTime.parse(Unknown Source)