我有一个像下面这样的字符串
Fri May 31 2019 05:08:40 GMT-0700 (PDT)
我想将其转换为类似yyyy-MM-dd.
我试过了。
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 ) ;
我收到错误:
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)
慕慕森
手掌心
慕丝7291255
相关分类