spring boot 2.0 + thymeleaf unix 时代至今
spring boot 2.0 + thymeleaf unix epoch to date
我是 spring boot 和 thymeleaf 的新手。我确实尝试研究了一段时间,但无法让它发挥作用。我正在调用第 3 方 api returns 一个对象,该对象在 unix 纪元时间戳中有一个字段。该值以 Long 形式返回。
在 thymeleaf 中,我在下面进行了尝试,但得到了一个完全不同的日期。时间戳是今天的。但是显示的日期是错误的。
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>
纪元值
1531879826
查看
<td th:text="${#dates.format(discount?.start, 'dd-MM-yyyy HH:mm:ss')}">date</td>
显示的日期有误。应该是今天的date/time.
18-01-1970 12:31:19
感谢任何引导我朝着正确方向前进的帮助。
为了正确处理,您必须为纪元时间使用更长的值。
在 java 中,您需要将其乘以 1000,因为它使用的是毫秒。
我假设:
<td th:text="${#dates.format(discount?.start * 1000, 'dd-MM-yyyy HH:mm:ss')}">date</td>
会完成任务的。
试试吧。
我是 spring boot 和 thymeleaf 的新手。我确实尝试研究了一段时间,但无法让它发挥作用。我正在调用第 3 方 api returns 一个对象,该对象在 unix 纪元时间戳中有一个字段。该值以 Long 形式返回。
在 thymeleaf 中,我在下面进行了尝试,但得到了一个完全不同的日期。时间戳是今天的。但是显示的日期是错误的。
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>
纪元值
1531879826
查看
<td th:text="${#dates.format(discount?.start, 'dd-MM-yyyy HH:mm:ss')}">date</td>
显示的日期有误。应该是今天的date/time.
18-01-1970 12:31:19
感谢任何引导我朝着正确方向前进的帮助。
为了正确处理,您必须为纪元时间使用更长的值。 在 java 中,您需要将其乘以 1000,因为它使用的是毫秒。
我假设:
<td th:text="${#dates.format(discount?.start * 1000, 'dd-MM-yyyy HH:mm:ss')}">date</td>
会完成任务的。
试试吧。