How to display time values in a specified format in the AnQi CMS template?
date
The filter can display time values in the specified format. But it should be noted thatdate
The input must be atime.Time
Otherwise, it cannot be processed and an error will be reported. The output format is set according to the Golang time format.
You can also usetime
, it anddate
The usage method and result are the same. It isdate
alias for .
How to use
date
How to use filters:
{{ obj|date:"时间格式" }}
For examplecreateTime
Formatted as2006-01-02
, you can write it like this:
# createTime 需为 time.Time 值
{{ createTime|date:"2006-01-02" }}
# 显示结果
2023-02-09
Sample Demo
{{ createTime|date:"2006-01-02" }}
# 显示结果
2023-02-09