date

將時間戳記轉換為另一種日期格式。此語法的格式與 strftime 相同。輸入使用與 Ruby 的 Time.parse 相同的格式。

輸入

{{ article.published_at | date: "%a, %b %d, %y" }}

輸出

Fri, Jul 17, 15

輸入

{{ article.published_at | date: "%Y" }}

輸出

2015

date 如果字串包含格式正確的日期,則適用於字串。

輸入

{{ "March 14, 2016" | date: "%b %d, %y" }}

輸出

Mar 14, 16

要取得目前時間,請將特殊詞 "now" (或 "today") 傳遞給 date

輸入

This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.

輸出

This page was last updated at 2024-10-23 00:46.

請注意,該值將是從範本最後一次產生頁面時的目前時間,而不是在涉及快取或靜態網站產生時向使用者呈現頁面時的時間。