我正在尝试将此日期转换为不同的格式。不幸的是,我无法成功解析日期并正确保留所有信息。
06-Dec-2017 07:14:56.656PM 转换为 2017-12-06 19:14:56.656
如果我尝试解析输入日期
LocalDateTime.parse("06-Dec-2017 07:14:56.656PM",
DateTimeFormatter.ofPattern("D-MMM-yyyy HH:mm:ss.SSSa"));
我遇到了以下错误 - 不确定它的含义是什么?
Exception in thread "main" java.time.format.DateTimeParseException: Text '06-Dec-2017 07:14:56.656PM' could not be parsed: Conflict found: Field MonthOfYear 1 differs from MonthOfYear 12 derived from 2017-01-06
at java.time.format.DateTimeFormatter.createError(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.LocalDateTime.parse(Unknown Source)
at com.cordys.coe.alf.logger.DBLogger.main(DBLogger.java:366)
Caused by: java.time.DateTimeException: Conflict found: Field MonthOfYear 1 differs from MonthOfYear 12 derived from 2017-01-06
at java.time.format.Parsed.crossCheck(Unknown Source)
at java.time.format.Parsed.crossCheck(Unknown Source)
如果尝试
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS")
.format((new SimpleDateFormat("DD-MMM-yyyy HH:mm:ss.SSSa")
.parse("06-Dec-2017 07:14:56.656PM"))));
它提供了以下内容,这可能会令人困惑,并且可能不正确。 2017-01-06 07:14:56:656
D
改为d
。根据JavaDocs的解释,D
表示一年中的天数,格式为数字,而且具体值为189
。因此,我认为你想使用的是小写字母d
。 - MadProgrammer