在 Thymeleaf 中格式化日期 [英] Formatting date in Thymeleaf
本文介绍了在 Thymeleaf 中格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Java/Spring/Thymeleaf 的新手,所以请忍受我目前的理解水平.我确实查看了这个类似的问题,但无法解决我的问题.
I'm brand new to Java/Spring/Thymeleaf so please bear with my current level of understanding. I did review this similar question, but wasn't able to solve my problem.
我正在尝试使用简化日期而不是长日期格式.
I'm trying to get a simplified date instead of the long date format.
// DateTimeFormat annotation on the method that's calling the DB to get date.
@DateTimeFormat(pattern="dd-MMM-YYYY")
public Date getReleaseDate() {
return releaseDate;
}
html:
<table>
<tr th:each="sprint : ${sprints}">
<td th:text="${sprint.name}"></td>
<td th:text="${sprint.releaseDate}"></td>
</tr>
</table>
电流输出
sprint1 2016-10-04 14:10:42.183
推荐答案
Bean 验证无所谓,你应该使用 Thymeleaf 格式:
Bean validation doesn't matter, you should use Thymeleaf formatting:
<td th:text="${#dates.format(sprint.releaseDate, 'dd-MMM-yyyy')}"></td>
还要确保您的 releaseDate
属性是 java.util.Date
.
Also make sure your releaseDate
property is java.util.Date
.
输出将类似于:04-Oct-2016
这篇关于在 Thymeleaf 中格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文