The timeliness and readability of website content largely depend on the accuracy and aesthetics of date and time information.AnQi CMS, as an efficient content management system, provides flexible tags and filters, which help us easily achieve personalized display of dates and timestamps, making your website content more in line with user habits and enhancing the overall reading experience.This article will delve into how to巧妙运用 these functions in AnQi CMS, transforming original time data into clear and understandable display formats.
Understanding date and time data in AnQi CMS
In AnQi CMS, the creation time of documents (CreatedTime)Update time(UpdatedTime)and such time information are usually expressed asUnix timestampstored in the database in the form of.This number format is convenient for internal processing and storage of the system, but when displayed on the front end, we need to convert it to the date and time format that users are accustomed to, such as "October 26, 2023 10:30:00".
core tools:stampToDatetags
AnQi CMS provides special formatting for timestampsstampToDateA tag that is simple, intuitive, and powerful, the preferred choice for handling timestamp display.
Its basic usage is:{{stampToDate(时间戳, "格式")}}.
- Timestamp: This refers to a 10-digit Unix timestamp, for example
1609470335This is the value you get from various tags in the Anqi CMS (such asarchiveDetail/archiveList), and the values of fields such asCreatedTimeorUpdatedTime. - Format:This is
stampToDateThe most flexible part of the tag. It follows the unique time formatting rules of the Go language. Unlike the commonYYYY-MM-DDpattern, Go language uses a fixed reference time -“January 02, 2006 03:04:05 PM -0700 MST”Define the format. You just need to use the corresponding number or English word in this reference time to represent the year, month, day, hour, minute, second, etc. you want in the format string.
For example:
- Want to display 'Year-Month-Day', the format string is
"2006-01-02". - Want to display 'Year/Month/Day Time:Minute', the format string is
"2006/01/02 15:04". - Want to display 'Month-Day Time:Minute', the format string is
"01-02 15:04". - The format string for displaying “English month abbreviation, Day, Year” is
"Jan 02, 2006".
**stampToDate