Spring Boot Thymeleaf 时间处理类

Spring Boot Thymeleaf About 2,450 words

Java LocalDateTime 类

获取当前时间

<div th:text="${#temporals.createNow()}"></div>
<div th:text="${#temporals.createNow().getClass()}"></div>

输出

2023-08-25T13:16:44.203614
class java.time.LocalDateTime

获取当前年月日时分秒(月份无需再转化)

<div th:text="${#temporals.year(#temporals.createNow())}"></div>
<div th:text="${#temporals.month(#temporals.createNow())}"></div>
<div th:text="${#temporals.day(#temporals.createNow())}"></div>

<div th:text="${#temporals.hour(#temporals.createNow())}"></div>
<div th:text="${#temporals.minute(#temporals.createNow())}"></div>
<div th:text="${#temporals.second(#temporals.createNow())}"></div>
<div th:text="${#temporals.nanosecond(#temporals.createNow())}"></div>

输出

2023
8
25

13
21
20
863644000

格式化时间

<div th:text="${#temporals.format(#temporals.createNow(), 'yyyy-MM-dd')}"></div>

输出

2023-08-25

其他方法

<div th:text="${#temporals.monthName(#temporals.createNow())}"></div>
<div th:text="${#temporals.monthNameShort(#temporals.createNow())}"></div>

<div th:text="${#temporals.dayOfWeek(#temporals.createNow())}"></div>
<div th:text="${#temporals.dayOfWeekName(#temporals.createNow())}"></div>
<div th:text="${#temporals.dayOfWeekNameShort(#temporals.createNow())}"></div>

输出

八月
8月

5
星期五
周五

Java Date 类

Date类与LocalDateTime类方法差不多。

<div th:text="${#dates.createNow()}"></div>
<div th:text="${#dates.format(#dates.createNow(), 'yyyy-MM-dd')}"></div>
<div th:text="${#dates.year(#dates.createNow())}"></div>
<div th:text="${#dates.month(#dates.createNow())}"></div>
<div th:text="${#dates.day(#dates.createNow())}"></div>
<div th:text="${#dates.hour(#dates.createNow())}"></div>
<div th:text="${#dates.minute(#dates.createNow())}"></div>
<div th:text="${#dates.second(#dates.createNow())}"></div>
<div th:text="${#dates.monthName(#dates.createNow())}"></div>
<div th:text="${#dates.monthNameShort(#dates.createNow())}"></div>
<div th:text="${#dates.dayOfWeek(#dates.createNow())}"></div>
<div th:text="${#dates.dayOfWeekName(#dates.createNow())}"></div>
<div th:text="${#dates.dayOfWeekNameShort(#dates.createNow())}"></div>

输出

Fri Aug 25 13:28:09 CST 2023
2023-08-25
2023
8
25
13
28
9
八月
8月
6
星期五
周五
Views: 663 · Posted: 2023-08-25

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh