legacy-knowledge-base
公開されました Sep. 10, 2025

Velocity テンプレートで $dateTool.toDate を使用すると、日付が返されません。

written-by

Antonio Ortega

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

  • Velocityテンプレートで、 dateTool.toDate を使って日付を取得しようとすると、デフォルトと異なるロケールを使用している場合は、期待通りに動作しません。
  • 例えば、以下のような条件のVelocityテンプレートがある場合、以下のようなコードになります。
#set ($dateStr = $dateTool.toDate( "EEE, dd MMM yyyy hh:mm:ss Z" , $reserved-article-display-date.data))

Date: $dateStr
  • 予定日を見るのではなく、変数 $dateStr の名前がどのように出力されるかを見ることにします。

Environment

  • Liferay Portal 6.2

解決策

  • $reserved-article-display-date.getData() を使用すると、デフォルトロケールのStringを返すので、この状況を回避するのに役立ちます。したがって、私たちの日付を適切に処理するために、 dateTool に、そのデフォルトロケールを示す必要があるだけです。
  • 以下のコードで解決できます:
#set ($dateStr = $dateTool.toDate( "EEE, dd MMM yyyy hh:mm:ss Z" , $reserved-article-display-date.getData(), $localeUtil.getDefault())

Date: $dateStr

追加情報

did-this-article-resolve-your-issue

legacy-knowledge-base