【Thymeleaf】格式化日期
生活随笔
收集整理的這篇文章主要介紹了
【Thymeleaf】格式化日期
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
前言
- 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模板所在目錄創(chuàng)建同名的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 這樣寫發(fā)生錯誤。將th:field 改為 th:value后正常。
Thymeleaf中的calendars對象
- #calendars : analogous to #dates, but for java.util.Calendar objects:
總結(jié)
以上是生活随笔為你收集整理的【Thymeleaf】格式化日期的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电信卡停机多久被注销(电信停复机多久之后
- 下一篇: spring boot-The temp