当前位置: 首页 > 知识库问答 >
问题:

无法分析,在索引23处找到未分析的文本

卫增
2023-03-14
start_date=2019-03-03T21:25:24.000Z&end_date=2019-03-03T21:25:29.000Z
    @GetMapping("/terminals")
    public ResponseEntity<Map<Integer, List<TopTerminalsDTO>>> getTopTerminals(
            @RequestParam(value = "start_date", required = true) String start_date,
            @RequestParam(value = "end_date", required = true) String end_date) {

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");
        LocalDateTime start_dateTime = LocalDateTime.parse(start_date, formatter);
        LocalDateTime end_dateTime = LocalDateTime.parse(end_date, formatter);

        final List<PaymentTransactionsDailyFacts> list = dashboardService.findTop_Terminals(start_dateTime, end_dateTime);
2019-03-10 13:22:46,677 INFO  [stdout] (default task-1) 13:22:46.676 [default task-1] ERROR o.s.b.w.s.support.ErrorPageFilter - Forwarding to error page from request [/dashboard/terminals] due to exception [Text '2019-03-03T21:22:39.000Z' could not be parsed, unparsed text found at index 23]
2019-03-10 13:22:46,678 INFO  [stdout] (default task-1) java.time.format.DateTimeParseException: Text '2019-03-03T21:22:39.000Z' could not be parsed, unparsed text found at index 23
2019-03-10 13:22:46,678 INFO  [stdout] (default task-1)     at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2049)
2019-03-10 13:22:46,678 INFO  [stdout] (default task-1)     at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1948)
2019-03-10 13:22:46,679 INFO  [stdout] (default task-1)     at java.base/java.time.LocalDateTime.parse(LocalDateTime.java:492)
2019-03-10 13:22:46,679 INFO  [stdout] (default task-1)     at deployment.datalis_admin.war//org.datalis.admin.backend.restapi.DashboardController.getTopTerminals(DashboardController.java:87)
2019-03-10 13:22:46,679 INFO  [stdout] (default task-1)     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
LocalDateTime start_dateTime = LocalDateTime.parse(start_date, DateTimeFormatter.ISO_INSTANT);
        LocalDateTime end_dateTime = LocalDateTime.parse(end_date, DateTimeFormatter.ISO_INSTANT);

我得到:23:15:21,554 INFO[stdout](默认任务-3)java.time.format.dateTimeParseException:无法解析文本'2019-03-19t23:15:14.000z':无法从TemporalAccessor获取LocalDateTime:{nanofsecond=0,instantseconds=1553037314,microofsecond=0,millifsecond=0},java.time.format.parsed类型的ISO

共有1个答案

斜宁
2023-03-14

这是因为根据您的dateTimeFormatterstart_date无效。在日期的最后有z是不可取的。

你有两个选择。

  1. start_date&end_date中删除z字符。
  2. 修改DateTimeFormatter以接受ZoneOffset。
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
LocalDateTime start_dateTime = LocalDateTime.parse("2019-03-03T21:25:24Z", DateTimeFormatter.ISO_INSTANT);
 类似资料: