我正在尝试以以下方式解析此字符串,但出现异常。谁能帮我吗?
String dateStr = "Thu 14 Feb 2019 15:05:48 +0200";
LocalDateTime datetime = LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern("EEE d MMM yyyy HH:mm:ss Z"));
例外:
java.time.format.DateTimeParseException: Text 'Thu 14 Feb 2019 15:05:48 +0200' could not be parsed at index 0
最佳答案
String dateStr = "Thu 14 Feb 2019 15:05:48 +0200";
Locale bLocale = new Locale.Builder().setLanguage("en").setRegion("US").build();
LocalDateTime datetime = LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern("EEE d MMM yyyy HH:mm:ss Z", bLocale));
System.out.println(datetime);
您应该创建一个语言环境作为参数。