springboot Thymeleaf中格式化jsr310新日期时间类(LocalDateTime,LocalDate)--thymeleaf格式化LocalDateTime,LocalDate等JDK8新时间类
依赖maven包
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency> <dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>2.4.1</version>
</dependency>
import nz.net.ultraq.thymeleaf.LayoutDialect;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect; @Configuration
public class TemplateConfiguration { @Bean
public Java8TimeDialect java8TimeDialect() {
return new Java8TimeDialect();
} @Bean
public LayoutDialect layoutDialect() {
return new LayoutDialect();
}
}
thymeleaf中格式化方法
<td th:text="${#temporals.format(bean.createTime, 'yyyy-MM-dd HH:mm:ss', locale)}"></td>
格式化效果:

官方提供的格式化方法:
/*
* =============================================================================
* See javadoc API for class org.thymeleaf.extras.java8time.expression.Temporals
* =============================================================================
*/ /*
* Format date with the standard locale format
* Also works with arrays, lists or sets
*/
${#temporals.format(temporal)}
${#temporals.arrayFormat(temporalsArray)}
${#temporals.listFormat(temporalsList)}
${#temporals.setFormat(temporalsSet)} /*
* Format date with the standard format for the provided locale
* Also works with arrays, lists or sets
*/
${#temporals.format(temporal, locale)}
${#temporals.arrayFormat(temporalsArray, locale)}
${#temporals.listFormat(temporalsList, locale)}
${#temporals.setFormat(temporalsSet, locale)} /*
* Format date with the specified pattern
* SHORT, MEDIUM, LONG and FULL can also be specified to used the default java.time.format.FormatStyle patterns
* Also works with arrays, lists or sets
*/
${#temporals.format(temporal, 'dd/MMM/yyyy HH:mm')}
${#temporals.arrayFormat(temporalsArray, 'dd/MMM/yyyy HH:mm')}
${#temporals.listFormat(temporalsList, 'dd/MMM/yyyy HH:mm')}
${#temporals.setFormat(temporalsSet, 'dd/MMM/yyyy HH:mm')} /*
* Format date with the specified pattern and locale
* Also works with arrays, lists or sets
*/
${#temporals.format(temporal, 'dd/MMM/yyyy HH:mm', locale)}
${#temporals.arrayFormat(temporalsArray, 'dd/MMM/yyyy HH:mm', locale)}
${#temporals.listFormat(temporalsList, 'dd/MMM/yyyy HH:mm', locale)}
${#temporals.setFormat(temporalsSet, 'dd/MMM/yyyy HH:mm', locale)} /*
* Format date with ISO-8601 format
* Also works with arrays, lists or sets
*/
${#temporals.formatISO(temporal)}
${#temporals.arrayFormatISO(temporalsArray)}
${#temporals.listFormatISO(temporalsList)}
${#temporals.setFormatISO(temporalsSet)} /*
* Obtain date properties
* Also works with arrays, lists or sets
*/
${#temporals.day(temporal)} // also arrayDay(...), listDay(...), etc.
${#temporals.month(temporal)} // also arrayMonth(...), listMonth(...), etc.
${#temporals.monthName(temporal)} // also arrayMonthName(...), listMonthName(...), etc.
${#temporals.monthNameShort(temporal)} // also arrayMonthNameShort(...), listMonthNameShort(...), etc.
${#temporals.year(temporal)} // also arrayYear(...), listYear(...), etc.
${#temporals.dayOfWeek(temporal)} // also arrayDayOfWeek(...), listDayOfWeek(...), etc.
${#temporals.dayOfWeekName(temporal)} // also arrayDayOfWeekName(...), listDayOfWeekName(...), etc.
${#temporals.dayOfWeekNameShort(temporal)} // also arrayDayOfWeekNameShort(...), listDayOfWeekNameShort(...), etc.
${#temporals.hour(temporal)} // also arrayHour(...), listHour(...), etc.
${#temporals.minute(temporal)} // also arrayMinute(...), listMinute(...), etc.
${#temporals.second(temporal)} // also arraySecond(...), listSecond(...), etc.
${#temporals.nanosecond(temporal)} // also arrayNanosecond(...), listNanosecond(...), etc. /*
* Create temporal (java.time.Temporal) objects from its components
*/
${#temporals.create(year,month,day)} // return a instance of java.time.LocalDate
${#temporals.create(year,month,day,hour,minute)} // return a instance of java.time.LocalDateTime
${#temporals.create(year,month,day,hour,minute,second)} // return a instance of java.time.LocalDateTime
${#temporals.create(year,month,day,hour,minute,second,nanosecond)} // return a instance of java.time.LocalDateTime /*
* Create a temporal (java.time.Temporal) object for the current date and time
*/
${#temporals.createNow()} // return a instance of java.time.LocalDateTime
${#temporals.createNowForTimeZone(zoneId)} // return a instance of java.time.ZonedDateTime
${#temporals.createToday()} // return a instance of java.time.LocalDate
${#temporals.createTodayForTimeZone(zoneId)} // return a instance of java.time.LocalDate /*
* Create a temporal (java.time.Temporal) object for the provided date
*/
${#temporals.createDate(isoDate)} // return a instance of java.time.LocalDate
${#temporals.createDateTime(isoDate)} // return a instance of java.time.LocalDateTime
${#temporals.createDate(isoDate, pattern)} // return a instance of java.time.LocalDate
${#temporals.createDateTime(isoDate, pattern)} // return a instance of java.time.LocalDateTime
参考:https://github.com/thymeleaf/thymeleaf-extras-java8time
springboot Thymeleaf中格式化jsr310新日期时间类(LocalDateTime,LocalDate)--thymeleaf格式化LocalDateTime,LocalDate等JDK8新时间类的更多相关文章
- 后端分页神器,mybatis pagehelper 在SSM与springboot项目中的使用
mybatis pagehelper想必大家都耳熟能详了,是java后端用于做分页查询时一款非常好用的分页插件,同时也被人们称为mybatis三剑客之一,下面 就给大家讲讲如何在SSM项目和sprin ...
- jdk8环境下sprngboot/springmvc中JSR310新日期/时间类LocalDateTime显示效果带T
如图所示: 日期时间类中带了一个T,以上这种格式LocalDateTime格式化的时候默认日期时间格式:ISO.DATE_TIME(按笔者目前的知识理解是ISO8601规范中的日期时间格式化) 想要把 ...
- Java日期时间API系列21-----Jdk8中java.time包中的新的日期时间API类,xk-time时间转换,计算,格式化,解析的工具
通过工作之余,对Java8中java.time包源码的不断学习,使用和总结,开发了xk-time,初步完成,欢迎试用和提出建议! xk-time xk-time is a datetime conve ...
- thymeleaf中的日期格式化
本篇介绍些thymeleaf中的日期格式化的方法: 1.用#dates.format来解决: <span th:text="${#dates.format(user.date, 'yy ...
- c++中利用localtime_s函数格式化输出当地日期与时间
Visual C++ 6.0开发环境中显示当地日期与时间主要通过localtime()函数来实现,该函数的原型在time.h头文件中,其语法格式如下: struct tm *localtime(xon ...
- Java日期时间API系列13-----Jdk8中java.time包中的新的日期时间API类,时间类转换,Date转LocalDateTime,LocalDateTime转Date等
从前面的系列博客中可以看出Jdk8中java.time包中的新的日期时间API类设计的很好,但Date由于使用仍非常广泛,这就涉及到Date转LocalDateTime,LocalDateTime转D ...
- JDK8中新日期时间API
它们面临的问题是:可变性:像日期和时间这样的类应该是不可变的.偏移性:Date中的年份是从1900开始的,而月份都从0开始.格式化:格式化只对Date有用,Calendar则不行.此外,它们也不是线程 ...
- Day029 JDK8中新日期和时间API (二)
# JDK8中新日期和时间API (二) Instant介绍 Instant:时间线上的一个瞬时点. 这可能被用来记录应用程序中的事件时间 戳. 在处理时间和日期的时候,我们通常会想到年,月,日,时, ...
- Day029 JDK8中新日期和时间API (四)
JDK8中新日期和时间API 其他的一些API ZoneId:该类中包含了所有的时区信息,一个时区的ID,如 Europe/Paris ZonedDateTime:一个在ISO-8601日历系统时区的 ...
随机推荐
- C# 数值计算、转换
1.保留小数位 今天再做到计算数值百分比的时候,刚开始试了几个都是不行: , num2 = ; double percent = num2 / num1; , num2 = ; double perc ...
- python练习题(二)
题目: 已知以下几期双色球号码(最后一个数字为蓝球), 2019080 03 06 08 20 24 32 07 2019079 01 03 06 09 19 31 16 2019078 01 17 ...
- 加密与解密 Sytem.Security.CryptoGraphy
一.Hash加密,使用HashAlgorithm哈希算法类的派生类 HashAlgorithm派生类包括: KeyedHashAlgorithm: 显示所有加密哈希算法实现均必须从中派生的抽象类. M ...
- VFD 时钟(VFD Clock with STM8 v2.0)
算是填了最先挖的VFD坑 最近pcb厂家神仙打架,为PCB普及做出了巨大贡献,到这事儿发生我也就开了两三次板,都赶上这个时间了,不开白不开! 不说了,上图! sch: pcb: 方案和之前的除了驱动电 ...
- 题解[51nod1555] 布丁怪
题解[51nod1555] 布丁怪 题面 解析 本文参考这位dalao的题解 首先有一个巧妙的转换, 开一个数组记录每个横坐标的纵坐标, 简单来说就是对于点(x,y),令a[x]=y. 于是问题就变成 ...
- 012_Python3 斐波纳契数列 + end 关键字
1.个斐波纳契数列. #!/usr/bin/python3 # Fibonacci series: 斐波纳契数列 # 两个元素的总和确定了下一个数 a, b = 0, 1 while b < ...
- 二十一.构建memcached服务、LNMP+memcached、PHP的本地Session信息、PHP实现session共享
proxy client web1 web2 1.构建memcached服务 ]# yum -y install memcached ]# cat /etc/sysconfig/memcached ...
- unsigned和signed
int分为unsigned(无正负号)和signed(有正负号) 一般int默认为signed unsigned和unsigned int意思相同
- 数据结构实验之查找五:平方之哈希表 (SDUT 3377)
Hash表的平方探测思路:如果当前这个没存放数值,就放进去,如果当前这个地方Hash [ i ] 已经有数值了,就以平方的间隔左右寻找没有存放数的空白 Hash [ i ]. #include < ...
- ros python 构造 pose
#!/usr/bin/env python import numpy as npfrom geometry_msgs.msg import Pose, Point, Quaternion, Twist ...