Thymeleaf中的日期格式化处理,使用内置对象

版权声明:本文为博主原创文章,未经博主允许也能转载,标明出处更好。 https://blog.csdn.net/fanpeizhong/article/details/88372935
<td th:text="${#dates.format(contractInfo.datePostpone, 'yyyy-MM-dd')}"></td>

其中的#dates是thymeleaf的内置工具对象。

dates: methods for java.util.Date objects: formatting, component extraction, etc.

附录:

内置基本对象(内置的基本对象可用#号直接访问。)

ctx: the context object.

vars: the context variables.

locale: the context locale.

request: (only in Web Contexts) the HttpServletRequest object.

response: (only in Web Contexts) the HttpServletResponse object.

session: (only in Web Contexts) the HttpSession object.

servletContext: (only in Web Contexts) the ServletContext object.

例子:

country: <span th:text="${#locale.country}">China</span>

内置工具对象

execInfo: information about the template being processed.

messages: methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{…} syntax.

uris: methods for escaping parts of URLs/URIs

conversions: methods for executing the configured conversion service (if any).

dates: methods for java.util.Date objects: formatting, component extraction, etc.

calendars: analogous to #dates, but for java.util.Calendar objects.

numbers: methods for formatting numeric objects.

strings: methods for String objects: contains, startsWith, prepending/appending, etc.

objects: methods for objects in general.

bools: methods for boolean evaluation.

arrays: methods for arrays.

lists: methods for lists.

sets: methods for sets.

maps: methods for maps.

aggregates: methods for creating aggregates on arrays or collections.

ids: methods for dealing with id attributes that might be repeated (for example, as a result of an iteration).

例子:

time:<span th:text="${#dates.format(date, 'yyyy-MM-dd HH:mm:ss')}">2018-03-18 22:03:08</span><br>

猜你喜欢

转载自blog.csdn.net/fanpeizhong/article/details/88372935