How to display time value in a specified format in Anqi CMS template?
date
The filter can display time values in a specified format. But be careful that,date
the input must be atime.Time
[en]Value, otherwise the processing cannot be performed and an error will be reported. The output format is set according to the Golang time format.
[en]You can also usetime
[en], it anddate
[en]are used in the same way and have the same result. It isdate
alias.
Usage Instructions
date
How to use the filter:
{{ obj|date:"时间格式" }}
For example, to transformcreateTime
formatted as2006-01-02
then it can be written like this:
# createTime 需为 time.Time 值
{{ createTime|date:"2006-01-02" }}
# 显示结果
2023-02-09
Here is an example demonstration
{{ createTime|date:"2006-01-02" }}
# 显示结果
2023-02-09