我是 Spring Boot 和 thymeleaf 的新手。我确实尝试研究了一段时间,但无法使其发挥作用。我正在调用一个第 3 方 api,它返回一个对象,该对象具有 unix 纪元时间戳中的字段。该值以 Long 形式返回。
在百里香中,我在下面尝试过,但得到了完全不同的日期。时间戳是今天的。但显示的日期是错误的。
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<!--<version>1.5.13.RELEASE</version> -->
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
纪元值
1531879826
Run Code Online (Sandbox Code Playgroud)
看法
<td th:text="${#dates.format(discount?.start, 'dd-MM-yyyy HH:mm:ss')}">date</td>
Run Code Online (Sandbox Code Playgroud)
显示日期错误。它应该是今天的日期/时间。
18-01-1970 12:31:19
Run Code Online (Sandbox Code Playgroud)
任何引导我走向正确方向的帮助都值得赞赏。