字符串到 LocalDateTime 的转换:java.time.format.DateTimeParseException
String to LocalDateTime conversion : java.time.format.DateTimeParseException
我正在使用以下代码转换字符串中的日期:
String strDate="Thu Aug 09 16:01:46 IST 2018";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
LocalDateTime dateTime = LocalDateTime.parse(strDate,formatter);
我遇到以下异常:
java.time.format.DateTimeParseException: Text 'Thu Aug 09 16:01:46 IST 2018' could not be parsed at index 0
变量 'strDate' 中的格式将相同且无法修改,因为我将从不同的应用程序中获取该格式
输入字符串的日期格式为:E MMM dd HH:mm:ss z yyyy
。下面的代码应该没有任何错误
public static void main(String[] args) throws IOException {
String strDate = "Thu Aug 09 16:01:46 IST 2018";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E MMM dd HH:mm:ss z yyyy");
LocalDateTime dateTime = LocalDateTime.parse(strDate, formatter);
}
我正在使用以下代码转换字符串中的日期:
String strDate="Thu Aug 09 16:01:46 IST 2018";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
LocalDateTime dateTime = LocalDateTime.parse(strDate,formatter);
我遇到以下异常:
java.time.format.DateTimeParseException: Text 'Thu Aug 09 16:01:46 IST 2018' could not be parsed at index 0
变量 'strDate' 中的格式将相同且无法修改,因为我将从不同的应用程序中获取该格式
输入字符串的日期格式为:E MMM dd HH:mm:ss z yyyy
。下面的代码应该没有任何错误
public static void main(String[] args) throws IOException {
String strDate = "Thu Aug 09 16:01:46 IST 2018";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E MMM dd HH:mm:ss z yyyy");
LocalDateTime dateTime = LocalDateTime.parse(strDate, formatter);
}