[JAVA] Get the current date and time by specifying the time zone in Thymeleaf

Expression Utility Objects #calendars

Use #calendars in Expression Utility Objects.

[Tutorial: Using Thymeleaf \ (ja ) --19 Appendix B: Expression Utility Object --Calendar](https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf_ja.html#%E3%82%AB%E3 % 83% AC% E3% 83% B3% E3% 83% 80% E3% 83% BC)

/*
 *Calendar object for the current date and time (java).util.Calendar)
 */
${#calendars.createNow()}

${#calendars.createNowForTimeZone()}

Sample code

Prepare template HTML.

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>

<!-- #calendars.createNow() -->
<p th:text="${#calendars.format(#calendars.createNow(), 'yyyy year MM month dd day HH hour mm minute ss second')}"></p>

<!-- #calendars.createNowForTimeZone('UTC') -->
<p th:text="${#calendars.format(#calendars.createNowForTimeZone('UTC'), 'yyyy year MM month dd day HH hour mm minute ss second')}"></p>

<!-- #calendars.createNowForTimeZone('Asia/Tokyo') -->
<p th:text="${#calendars.format(#calendars.createNowForTimeZone('Asia/Tokyo'), 'yyyy year MM month dd day HH hour mm minute ss second')}"></p>

<!-- #calendars.createNowForTimeZone('GMT+0900') -->
<p th:text="${#calendars.format(#calendars.createNowForTimeZone('GMT+0900'), 'yyyy year MM month dd day HH hour mm minute ss second')}"></p>

</body>
</html>

Run in Japanese / Japanese environment with time zone and locale

-# calendars.createNow (),'Asia / Tokyo','GMT + 0900' are output in Japan Standard Time --'UTC' is output in Coordinated Universal Time (9 hours before Japan)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>

<!-- #calendars.createNow() -->
<p>September 14, 2019 09:01:23</p>

<!-- #calendars.createNowForTimeZone('UTC') -->
<p>September 14, 2019 00:01:23</p>

<!-- #calendars.createNowForTimeZone('Asia/Tokyo') -->
<p>September 14, 2019 09:00:23</p>

<!-- #calendars.createNowForTimeZone('GMT+0900') -->
<p>September 14, 2019 09:00:23</p>

</body>
</html>

This environment

Reference material

-[Tutorial: Using Thymeleaf \ (ja ) --19 Appendix B: Expression Utility Object-Calendar](https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf_ja.html#%E3%82%AB% E3% 83% AC% E3% 83% B3% E3% 83% 80% E3% 83% BC)

Recommended Posts

Get the current date and time by specifying the time zone in Thymeleaf
Format the date and time given by created_at
[Java] How to get the current date and time and specify the display format
Parse the date and time string formatted by the C asctime function in Java
[Swift] Get the current time numerically
How to get the date in java
How to get the current date as a string in yyyyMMdd format
Which class should I use to get the date and time in my Rails app (Time, DateTime, TimeWithZone)
Date and time
[Java] Get and display the date 10 days later using the Time API added from Java 8.
Java Unit Test Library-Determine if Artery-Date, Calendar, long is the current date and time (specify tolerance in minutes)
Change date and time to Japanese notation in Rails
[Java] How to get the key and value stored in Map by iterative processing
Usability of date and time classes in each language
# 1_JAVA I want to get the index number by specifying one character in the character string.
Handling of date and time in Ruby. Use Date and Time properly.
[Ruby] How to get the value by specifying the key. Differences between hashes, symbols and fetch
Get the next business day after the specified date in JAVA
Install by specifying the version of Django in the Docker environment
Set the date and time from the character string with POI
Set the time zone in the JVM of your Azure application
[Java] Use ResolverStyle.LENIENT to handle the date and time nicely
View current date in Java
[Rails] Get access_token at the time of Twitter authentication with Sorcery and save it in DB
[Learning record] I got the current time in Ruby and output a different greeting for each time.
[Java] Get date information 10 days later using milliseconds in the Date class
[Java] Get the dates of the past Monday and Sunday in order
The design concept of Java's Date and Time API is interesting
Put the date (e.g. yyyy-MM-dd) in the log file output by logback
The relationship between strict Java date checking and daylight savings time
Create a calendar from the Calendar class by specifying the year and month
[Android] Get the date on Monday
[MySQL] [java] Receive date and time
Add the date to the GC statistics acquired by gcutil and output it.
This and that of the implementation of date judgment within the period in Java
Get the value of enum saved in DB by Rails with attribute_before_type_cast
How to create your own annotation in Java and get the value
Let's create a TODO application in Java 9 Create TODO display Sort by date and time + Set due date default to today's date