【发布时间】:2016-07-19 06:29:51
【问题描述】:
我正在尝试在 java 8 中将 String 转换为 LocalDateTime 对象。下面是我的代码。
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Test {
public static void main(String[] args){
String text = "27/11/2016 11:10 pm";
LocalDateTime date = LocalDateTime.parse(text, DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm a"));
System.out.println(date);
}
}
下面是我遇到的错误。
Exception in thread "main" java.time.format.DateTimeParseException: Text '27/11/2016 11:10 pm' could not be parsed at index 17
【问题讨论】: