Reputation: 43
I want list like:
<ul>
<li>2017-01-31</li> <!-- I want today date -->
<li>2017-02-01</li> <!-- I want tomorrow date -->
<li>2017-02-02</li> <!-- I want next day date -->
</ul>
Now I have only first li
:
<ul>
<li>th:text="${#dates.format(#dates.createToday(), 'yyyy-MM-dd')</li>
</ul>
How to get next date ( like: #dates.createToday() + "1 day"
)?
Upvotes: 1
Views: 1237
Reputation: 20487
This is something that thymeleaf just doesn't do well... that being said, if you include common-lang3 in your pom, you can get it working like this:
POM:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
Thymeleaf:
<ul>
<li th:each="i: ${#numbers.sequence(0,2)}" th:with="util=${T(org.apache.commons.lang3.time.DateUtils)},date=${util.addDays(#dates.createToday(), i)}" th:text="${#dates.format(date, 'yyyy-MM-dd')}" />
</ul>
I would recommend that you add the dates in your controller (creating them in the java, which is easy), and then just loop and format in thymeleaf.
Upvotes: 3