In website content management, the accurate and aesthetically pleasing presentation of time is crucial for user experience.Whether it is the publication date of the article, the update time of the product, or the submission time of the comments, a clear and consistent time format can significantly enhance the readability and professionalism of the content.AnQi CMS as an efficient and flexible content management system, deeply understands this, and provides a powerful and simple tool for template developers——stampToDateThe tag is used specifically to format timestamps into various custom date and time display formats.

UnderstandingstampToDateTag

stampToDateThe core function of the label is to convert a standard 10-digit Unix timestamp (i.e., the number of seconds from 00:00:00 UTC on January 1, 1970, to the current time) into a human-readable date and time string.This tag can be used directly in the template language of Anqi CMS without complex logic processing, greatly simplifying the display of time information.For example, when we need to display the creation time of an article (usually stored in timestamp format),stampToDateCan fully demonstrate its abilities, converting it into formats such as 'October 26, 2023' or '10:30 AM'.

stampToDateThe syntax structure of the tag.

stampToDateThe syntax structure of the tag is intuitive and easy to master, its basic form is{{stampToDate(时间戳, "格式")}}.

Among them,时间戳Part is expected to be a 10-digit integer representing a Unix timestamp. In Anqi CMS templates, this usually comes from a database field, such as an article object (archive) or list items (item)的CreatedTimeorUpdatedTimeattributes. For example:item.CreatedTimeIt will provide a 10-digit timestamp.

格式A string defines the specific format you want the timestamp to be displayed in.It should be especially noted that the Anqi CMS uses a unique "reference time" mode in time formatting in its underlying Go language.You are not using likeYYYY-MM-DDInstead of such an abstract placeholder, it uses specific reference date and time values in the Go language to define the format. This reference time is fixed to:2006年1月2日 15时4分5秒It is, to the millisecond and time zone2006-01-02 15:04:05.999999999 -0700 MSTThis means that if you want to display the year, you need to use2006as a placeholder in the format string; to display the month, use01; for the date use02and so on.

stampToDateexample of practical application

Let's understand through some specific examplesstampToDateflexible application. Suppose we have a timestamp variablepublishStampIts value is1609470335Corresponding to January 1, 2021, 12:25:35 PM.

To format it into a common 'year-month-day' format, such as '2021-01-01', you can use the following format:

<div>{{stampToDate(publishStamp, "2006-01-02")}}</div>

If you need to display a Chinese date format, for example, "2021-01-01":

<div>{{stampToDate(publishStamp, "2006年01月02日")}}</div>

For the need to display time only (e.g. "12:25" or "12:25:35"), the formatted string will focus on the hour, minute, and second parts:

<div>{{stampToDate(publishStamp, "15:04")}}</div>
<div>{{stampToDate(publishStamp, "15:04:05")}}</div>

Combining the date and time can achieve a more comprehensive display, for example, "2021-01-01 12:25:35":

<div>{{stampToDate(publishStamp, "2006-01-02 15:04:05")}}</div>

In the actual content list, for example, when usingarchiveListLabels are displayed in a loop when articles are shown,item.CreatedTimeanditem.UpdatedTimeThe field is usually a 10-digit timestamp. At this time,