关于依赖项:
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.0.12.RELEASE</version>
</dependency>
如果您将使用Java 8的新日期包中的LocalDate
、LocalDateTime
或其他任何类,则应添加此附加依赖项。
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
关于您的日期对象类型,如果您使用Date
,
<td th:text="${#dates.format(sprint.releaseDate, 'dd-MM-yyyy HH:mm')}">30-12-2021 23:59</td>
如果您使用
LocalDate
或
LocalDateTime
,
<td th:text="${#temporals.format(sprint.releaseDate, 'dd-MM-yyyy HH:mm')}">30-12-2021 23:59</td>
仍然有一种选择是在您的模型属性中传递一个 DateTimeFormatter
对象
context.setVariable("df", DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm"));
model.addAttribute("df", DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm"));
<td th:text="${df.format(sprint.releaseDate)}">30-12-2021 23:59</td>
这篇文章也许可以帮助您更深入地了解
Thymeleaf中的日期。
或
@java.util.Locale@ENGLISH`。 - cbreezier