在 Thymeleaf 中格式化日期

编程入门 行业动态 更新时间:2024-10-24 07:24:06
本文介绍了在 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 中格式化日期

本文发布于:2023-05-28 12:29:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/320912.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   Thymeleaf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!