我想Instant使用 Java 的预定义格式来格式化。我可以在 Java 中做到这一点:
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, request.getLocale());
// this will hopefully format a Date to 12.09.2018 02:10
我希望使用我的Instant类型在 Thymeleaf 中完成此操作:
<div th:text="${#temporals.format(work.indexTime)}"></div>
<!-- this will print "2018-09-12T02:10:06Z" -->
但是我怎么能告诉 Thymeleaf 使用这些DateFormat.SHORT设置呢?
编辑:
我目前的解决方法是这样的:
控制器:
DateTimeFormatter dateFormatter = DateTimeFormatter
.ofLocalizedDateTime(FormatStyle.SHORT)
.withLocale(request.getLocale())
.withZone(ZoneId.systemDefault());
模板:
<div th:text="${dateFormatter.format(work.indexTime)}"></div>
倚天杖
繁花不似锦
相关分类