【Thymeleaf】格式化日期
前言
- thymeleaf 3.0
- spring boot 2.0.0RELEASE
无国际化:格式化日期
<p>Today is: <span th:text="${#calendars.format(today,'yyyy-MM-dd')}">2019-08-01</span>
</p>
国际化:格式化日期
spring boot国际化:https://www.cnblogs.com/GoodHelper/p/6824492.html
Thymeleaf国际化:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#a-multi-language-welcome
安装Thymeleaf国际化方法,需要在Thymeleaf模板所在目录创建同名的properties文件。模板名为home.html,同名的properties文件为home_zh.properties(中文)、home_en.properties(英文)。
home_zh.properties:
date.format=yyyy年MM月dd日
home_en.properties:
date.format=MMMM dd'','' yyyy
准备好同名的properties文件后,在Thymeleaf中格式化日期:
<p th:with="df=#{date.format}">Today is: <span th:text="${#calendars.format(today,df)}">2019-08-01</span>
</p>
或
<p>Today is: <span th:with="df=#{date.format}" th:text="${#calendars.format(today,df)}">2019-08-01</span>
</p>
th:field 陷阱
<div class="form-group"> <label class="col-sm-3 control-label">钉钉提报时间:</label><div class="col-sm-8"><input name="dingTime" th:field="*{#calendars.format(dingTime,'yyyy-MM-dd')}" class="form-control" type="text" readonly="readonly" ></div>
</div>
th:field
这样写发生错误。将th:field
改为th:value
后正常。
Thymeleaf中的calendars对象
- #calendars : analogous to #dates, but for java.util.Calendar objects:
/** ======================================================================* See javadoc API for class org.thymeleaf.expression.Calendars* ======================================================================*//** Format calendar with the standard locale format* Also works with arrays, lists or sets*/
${#calendars.format(cal)}
${#calendars.arrayFormat(calArray)}
${#calendars.listFormat(calList)}
${#calendars.setFormat(calSet)}/** Format calendar with the ISO8601 format* Also works with arrays, lists or sets*/
${#calendars.formatISO(cal)}
${#calendars.arrayFormatISO(calArray)}
${#calendars.listFormatISO(calList)}
${#calendars.setFormatISO(calSet)}/** Format calendar with the specified pattern* Also works with arrays, lists or sets*/
${#calendars.format(cal, 'dd/MMM/yyyy HH:mm')}
${#calendars.arrayFormat(calArray, 'dd/MMM/yyyy HH:mm')}
${#calendars.listFormat(calList, 'dd/MMM/yyyy HH:mm')}
${#calendars.setFormat(calSet, 'dd/MMM/yyyy HH:mm')}/** Obtain calendar properties* Also works with arrays, lists or sets*/
${#calendars.day(date)} // also arrayDay(...), listDay(...), etc.
${#calendars.month(date)} // also arrayMonth(...), listMonth(...), etc.
${#calendars.monthName(date)} // also arrayMonthName(...), listMonthName(...), etc.
${#calendars.monthNameShort(date)} // also arrayMonthNameShort(...), listMonthNameShort(...), etc.
${#calendars.year(date)} // also arrayYear(...), listYear(...), etc.
${#calendars.dayOfWeek(date)} // also arrayDayOfWeek(...), listDayOfWeek(...), etc.
${#calendars.dayOfWeekName(date)} // also arrayDayOfWeekName(...), listDayOfWeekName(...), etc.
${#calendars.dayOfWeekNameShort(date)} // also arrayDayOfWeekNameShort(...), listDayOfWeekNameShort(...), etc.
${#calendars.hour(date)} // also arrayHour(...), listHour(...), etc.
${#calendars.minute(date)} // also arrayMinute(...), listMinute(...), etc.
${#calendars.second(date)} // also arraySecond(...), listSecond(...), etc.
${#calendars.millisecond(date)} // also arrayMillisecond(...), listMillisecond(...), etc./** Create calendar (java.util.Calendar) objects from its components*/
${#calendars.create(year,month,day)}
${#calendars.create(year,month,day,hour,minute)}
${#calendars.create(year,month,day,hour,minute,second)}
${#calendars.create(year,month,day,hour,minute,second,millisecond)}${#calendars.createForTimeZone(year,month,day,timeZone)}
${#calendars.createForTimeZone(year,month,day,hour,minute,timeZone)}
${#calendars.createForTimeZone(year,month,day,hour,minute,second,timeZone)}
${#calendars.createForTimeZone(year,month,day,hour,minute,second,millisecond,timeZone)}/** Create a calendar (java.util.Calendar) object for the current date and time*/
${#calendars.createNow()}${#calendars.createNowForTimeZone()}/** Create a calendar (java.util.Calendar) object for the current date (time set to 00:00)*/
${#calendars.createToday()}${#calendars.createTodayForTimeZone()}
【Thymeleaf】格式化日期相关推荐
- thymeleaf格式化日期传参写法隐藏域
格式化日期 <span th:text="${#dates.format(user.bir, 'yyyy-MM-dd HH:mm')}"></span> 日 ...
- thymeleaf如何格式化日期?
Thymeleaf主要使用org.thymeleaf.expression.Dates这个类来处理日期,在thymeleaf模板中使用"#dates来表示这个对象. 1.格式化日期 [[${ ...
- JSTL fmt标签格式化日期时分秒显示为00:00:00和12:00:00问题
2019独角兽企业重金招聘Python工程师标准>>> 记录下今天fmt格式化日期时分秒碰到的坑吧,今天用fmt:formatDate标签格式化一个日期的时候HH:mm:ss还是hh ...
- R语言用户自定义函数的语法结构、编写自定义统计值计算函数(使用ifelse结构计算均值和标准差等)、编写自定义日期格式化(format)函数(switch函数使用不同分枝格式化日期数据)、应用自定函数
R语言用户自定义函数的语法结构.编写自定义统计值计算函数(使用ifelse结构计算均值和标准差等).编写自定义日期格式化(format)函数(switch函数使用不同分枝格式化日期数据).应用自定函数 ...
- Java格式化日期用斜杠_[java工具类01]__构建格式化输出日期和时间的工具类
在之前的学习中,我写过一篇关于字符串格式化的,就主要设计到了时间以及日期的各种格式化显示的设置,其主要时通过String类的fomat()方法实现的. 我们可以通过使用不同的转换符来实现格式化显示不同 ...
- window powershell 获取前后日期,格式化日期
today" 昨天 "昨天是:today.AddDays(-1))" 明天 "明天是:today.AddDays(1))" 一周前 "一周前 ...
- 如何使用LocalDateTime解析/格式化日期? (Java 8)
本文翻译自:How to parse/format dates with LocalDateTime? (Java 8) Java 8 added a new java.time API for wo ...
- Convert函数应用格式化日期
SqlServer里convert函数格式化日期 格式:CONVERT(data_type,expression[,style]) 说明:此样式一般在时间类型(datetime,smalldateti ...
- 时间戳转格式化日期,日期转换成时间戳
1.时间戳转格式化日期,比如:1384936600 → 2013-11-20 08:36:40 输入一个long,输出一个nsstring 2.反过来:2013-11-20 08:36:40 → 1 ...
最新文章
- 免费正则表达式辅助工具(转)
- 不是微型计算机主板上的部件,微型计算机主板上安装的主要部件
- CL_GUI_PICTURE
- python替换缺失值_详解Pandas 处理缺失值指令大全
- SQL里的SWITCH分支语句
- 统计学习方法读书笔记10-决策树
- idea运行前端项目
- 太全面了,RF接口自动化框架项目实战
- ASDM的网管的环境搭建
- 【小笔记】大数据量excel解析工具性能对比
- 网页端下载喜马拉雅音频
- C语言克莱姆法解方程组解析,解线性方程组用克莱姆法则
- 历代iPad主要参数对比,更新于2021年09月
- 线性代数 | (3) 行列式
- JavaScript常见问题及答案
- 『杭电1900』Gangs
- 鸿蒙王者荣耀想要转区吗,王者荣耀转区注意事项 你了解了吗
- mac上Apk反编译工具合集整理与资源
- 用流对象的成员函数控制输出格式
- Java多进程从头讲到尾,值得收藏!