gpt4 book ai didi

spring boot 2.0 + thymeleaf unix 时代至今

转载 作者:行者123 更新时间:2023-12-02 03:32:34 24 4
gpt4 key购买 nike

我是 spring boot 和 thymeleaf 的新手。我确实尝试研究了一段时间,但无法让它发挥作用。我正在调用第 3 方 api,它返回一个对象,该对象在 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>

时代值(value)

1531879826

查看

<td th:text="${#dates.format(discount?.start, 'dd-MM-yyyy HH:mm:ss')}">date</td>

显示的日期是错误的。它应该是今天的日期/时间。

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 2.0 + thymeleaf unix 时代至今,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51411076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com