date

巴克励步

发布于:2025-01-02

将时间戳(timestamp)转换为另一种日期格式。格式化语法与 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 2020-05-01 14:41.
注意,上述实例输出的日期是最后一次生成当前页面的时间,并不是页面呈现给用户的时间。
提交反馈