romach
4/22/2017 - 1:05 AM

Format LocalDateTime with Thymeleaf

Format LocalDateTime with Thymeleaf

# build.gradle
dependencies {
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.thymeleaf.extras:thymeleaf-extras-java8time')
}
# application.properties
thymeleaf.version=3.0.2.RELEASE
thymeleaf-layout-dialect.version=2.1.1
# template.html
<tbody>
    <th:block th:each="campaign : ${campaigns}">
        <tr>
            <td th:text="${#temporals.format(campaign.startTime(), 'yyyy-MM-dd HH:mm:ss')}">startTime</td>
        </tr>
    </th:block>
</tbody>
ble>
@Configuration
public class ProgramConfiguration {

    @Bean
    public IDialect conditionalCommentDialect() {
        return new Java8TimeDialect();
    }
}