日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【Thymeleaf】格式化日期

發(fā)布時間:2024/9/19 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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:
/** ======================================================================* 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()}

總結(jié)

以上是生活随笔為你收集整理的【Thymeleaf】格式化日期的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。