Datetime 在Java 8中将字符串转换为日期时间时出错

Datetime 在Java 8中将字符串转换为日期时间时出错,datetime,java-8,Datetime,Java 8,我正在尝试将字符串转换为Java8中的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";

我正在尝试将字符串转换为Java8中的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
使用
String text=“27/11/2016 11:10 PM”

必须使用大写字母。

使用
String text=“27/11/2016 11:10 PM”


它必须用大写字母。

am/pm
需要大写字母

String text = "27/11/2016 11:10 PM";
LocalDateTime date = LocalDateTime.parse(text, DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm a"));
每日上午一点下午一点


上午/下午的
am/pm
需要大写字母

String text = "27/11/2016 11:10 PM";
LocalDateTime date = LocalDateTime.parse(text, DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm a"));
每日上午一点下午一点


它可以工作。但是我正在从引导数据采集器获取I/p,它就像是am/pm一样。在将值发送到解析方法之前,您不能将其转换为大写吗?你能给我举个真实的例子吗?thnx@anything在调用parse之前将其转换为大写。@realponsign或使用不区分大小写的格式化程序……它可以工作。但是我正在从引导数据采集器获取I/p,它就像是am/pm一样。在将值发送到解析方法之前,您不能将其转换为大写吗?你能给我举个真实的例子吗?thnx@anything在调用parse之前将其转换为大写。@realpoint或使用不区分大小写的格式化程序。。。