我有一个旧程序,并将其升级到Java 8.现在我想利用LocalDateTime。我已更新实体并在数据库中的值为10-APR-1990
。从使用to_date和测试LocalTimeDate的数据库测试日期
但是我收到以下错误:
java.time.format.DateTimeParseException: Text '10-APR-90' could not be parsed at index 3
在我的测试我尝试使用DateTimeFormatter
解析它。
测试:
@Test
public void testLocalDateTime() throws Exception {
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("dd-MMM-yy", Locale.US);
Tcan1990 applicant = tcan1990Repository.findOne(new Tcan1990PK("000000009", 888067));
assertEquals(LocalDateTime.parse("10-APR-90",formatter),applicant.getPymtDt());
}
我无法添加'applicant.getPymtDt()。atStartOfDay()',我仍然收到相同的错误。该字段为LocalDateTIme – Drew1208
更新的代码以删除atStartOfDay()。有没有在你传递的字符串中有一段时间?断言将失败。你可以断言只是当地的日期部分? assertEquals(LocalDate.parse(“10-APR-1990”,formatter),applicant.getPymtDt()。toLocalDate()); – Veeram
我的IDE是'不可转换的类型LocalDate和LocalDateTime'的警告,我得到和错误说'java.lang.AssertionError: 预计:2008-02-08 实际:2008-02-08T00:00'所以它似乎是工作,但我需要修复解析 – Drew1208