Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the Thymeleaf date object

Shulou Source: shulou.com Published: 2022-06-01 23:58:00 10月13日 Update

The knowledge of this article "Thymeleaf date object how to use" is not understood by most people, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Thymeleaf date object how to use" article.

Thymeleaf uses # dates or # calendars objects in the template to handle dates, which are mostly similar.

Development environment: IntelliJ IDEA 2019.2.2

Spring Boot version: 2.1.8

Create a new Spring Boot project named demo.

1 、 pom.xml

Join Thymeleaf dependency

Org.springframework.boot spring-boot-starter-thymeleaf

2 、 src/main/resources/application.yml

Set the template cache to false so that you can see the results immediately after modifying the html page and refreshing the browser.

Spring: thymeleaf: cache: false

3 、 src/main/java/com/example/demo/TestController.java

Package com.example.demo;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import java.util.*;@Controllerpublic class TestController {@ RequestMapping ("/") public String test (Model model) {Calendar cal = Calendar.getInstance (); Date date = cal.getTime (); Calendar cal1 = Calendar.getInstance (); Calendar cal2 = Calendar.getInstance () Cal1.add (Calendar.DATE, 1); cal2.add (Calendar.DATE, 2); Date [] arr = new Date [] {cal1.getTime (), cal2.getTime ()}; List list = Arrays.asList (arr); Set set = new HashSet (list); model.addAttribute ("date", date); model.addAttribute ("cal", cal); model.addAttribute ("arr", arr) Model.addAttribute ("list", list); model.addAttribute ("set", set); return "test";}

4 、 src/main/resources/templates/test.html

Format date format (date) formatISO (date) format (date,'yyyy-MM-dd HH:mm:ss') format (cal) formatISO (date) format (date,'yyyy-MM-dd HH:mm:ss') arrayFormat (arr) listFormat (list 'yyyy-MM-dd') setFormat (set) get date day (date) Day month (date) month monthName (date) month name monthNameShort (date) month name year (date) year dayOfWeek (date) Day Index dayOfWeekName (date) days of the week dayOfWeekNameShort (date) days of the week hour (date) minute (date) minutes second (date) seconds millisecond (date) milliseconds

Browser access: http://localhost:8080

Page output:

Format date format (date) 13 October 2019 10:35:32 formatISO (date) 2019-10-13T22:35:32.484+08:00format (date,'yyyy-MM-dd HH:mm:ss') 2019-10-13 22:35:32format (cal) 10:35:32 October 13, 2019 formatISO (date) 2019-10-13T22:35:32.484+08:00format (date) 'yyyy-MM-dd HH:mm:ss') 2019-10-13 22:35:32arrayFormat (arr) 14 October 2019 10:35:32 afternoon 15 October 2019 10:35:32 listFormat (list) 'yyyy-MM-dd') 2019-10-142019-10-15setFormat (set) 15 October 2019 10:35:32 October 14, 2019 10:35:32 acquisition date day (date) Day 13month (date) month 10monthName (date) month name October monthNameShort (date) month name October year (date) year 2019dayOfWeek (date) Index of days of the week 1dayOfWeekName (date) name Sunday dayOfWeekNameShort (date) days of the week abbreviated as Sunday hour (date) 22minute (date) minutes 35second (date) seconds 32millisecond (date) milliseconds or more is the content of the article "how to use Thymeleaf date objects" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Name date week month object content two most year article format template browser knowledge article index page browse value that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker vpn Shulou Technology MySQL