基本上我想将格式为'hh:mm'的DateTimeFormatter应用于我从'zonedDateTime.toLocalTime()'对象获得的值并将其存储为LocalTime对象,以便我得到像'08:00'这样的值,如下代码显示了我如何获取特定时区的当前时间,并在格式化时尝试将其转换为名为“currentTime”的 LocalTime:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm");
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of(appTheme.getTimezone()));
LocalTime currentTime = LocalTime.parse(zonedDateTime.toLocalTime().toString(),formatter);
现在由于某种未知原因,我从上面的最后一行代码中得到以下错误:
java.time.format.DateTimeParseException: Text '15:32:03.824' could not be parsed, unparsed text found at index 5
java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1952)
java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
java.time.LocalTime.parse(LocalTime.java:441)
io.apptizer.cafe.controller.CategoryController.getBusinessCategoryDetails(CategoryController.java:789)
io.apptizer.cafe.controller.CategoryController.backwardCompatibilityCategories(CategoryController.java:387)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
io.apptizer.cafe.filter.SessionHandleFilter.doFilter(SessionHandleFilter.java:39)
我希望我能很好地解释我的问题,我的主要目标是获取 'hh:mm' 或 'HH:mm' 格式的 'zonedDateTime.toLocalTime()' 值并将其存储为 LocalTime 对象,我只是可以实现它,因为是否出现错误,
如果有人能帮忙就好了,干杯!