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.

请注意,该值将是上次从模板生成页面时的当前时间,而不是如果涉及缓存或静态站点生成时向用户呈现页面的时间。