【问题标题】:Is there a way to use #dates in Thymeleaf to only include day, month, and year while keeping locale formatting?有没有办法在 Thymeleaf 中使用 #dates 来仅包含日、月和年,同时保持区域设置格式?
【发布时间】:2019-11-29 19:30:40
【问题描述】:

<div th:text="${#dates.format(204587433443L)}"></div给了

June 25, 1976 5:50:33 PM EDT 英文,和

25 juin 1976 17:50:33 EDT 法语

我只想要日、月和年,同时仍然保持语言特定的格式,如下所示:

June 25, 1976 表示英语,以及

25 juin 1976 表示法语。

我尝试过<div th:text="${#dates.format(204587433443L, 'MMMM dd, yyyy')}"></div,但结果是juin 25, 1976,这不是我想要的。


【问题讨论】:

标签: date thymeleaf locale


【解决方案1】:

您可以为每种文化使用切换条件:

<div th:switch="${#locale}"> 
<p th:case="'en-US'">
   // us colture format MMMM dd YYYY
<p th:case="'fr-FR '">
  // us colture format dd MMMM YYYY

【讨论】:

    猜你喜欢
    • 2017-11-06
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 2018-10-31
    • 2020-10-11
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    相关资源
    最近更新 更多