Thymeleaf does not have a built-in Utility to operate the Java 8 date and time API by default.
Include and use thymeleaf-extras-java8time
.
java.util.Date
and java.util.Calendar
, #dates
and #calendars
are provided by default.Add the dependency of thymeleaf-extras-java8time
.
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
** * From spring-boot 1.4.0, it is no longer necessary to register Dialect in the DI container ***
~~ To be able to use it with Spring Boot, Dialect must be registered in the DI container. I will write an example of creating and registering a dedicated Configuration. ~~
@Configuration
public class ThymeleafExtrasConfiguration {
@Bean
public Java8TimeDialect java8TimeDialect() {
return new Java8TimeDialect();
}
}
You will be able to call it as follows.
${#temporals.format(hogeDateTime, 'dd/MMM/yyyy HH:mm')}
Recommended Posts