日期格式处理EEE MMM dd HH:mm:ss 'GMT'zz yyyy
String dateTimeString = "Sun Mar 12 01:01:01 GMT+08:00 2023";
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.appendPattern("EEE MMM dd HH:mm:ss 'GMT'zz yyyy")
.toFormatter().withLocale(Locale.ENGLISH);
try {
ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeString, formatter);
System.out.println("Parsed ZonedDateTime: " + zonedDateTime);
} catch (DateTimeParseException e) {
System.err.println("Error parsing date: " + e.getMessage());
}
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.appendPattern("EEE MMM dd HH:mm:ss 'GMT'zz yyyy")
.toFormatter().withLocale(Locale.ENGLISH);
try {
ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeString, formatter);
System.out.println("Parsed ZonedDateTime: " + zonedDateTime);
} catch (DateTimeParseException e) {
System.err.println("Error parsing date: " + e.getMessage());
}
本文来自博客园,作者:life_start,转载请注明原文链接:https://www.cnblogs.com/yangh2016/p/18110045