How to use the `stampToDate` tag to format timestamps in the Anqi CMS template?

Calendar 👁️ 61

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,

Related articles

How to use `for` loop and `if` conditional judgment tags in Anqi CMS template?

As an experienced Anqi CMS website operation personnel, I am very clear about the core role of templates in content presentation.A flexible and efficient template can not only enhance the user experience but also help us achieve accurate content placement and management.In the Anqi CMS template system, the `for` loop and `if` conditional judgment tags are the two cornerstones for building dynamic and interactive web pages.They make content no longer static text blocks, but can intelligently display according to data changes.

2025-11-06

How to use the `tagDataList` tag to display documents under a specified Tag in the AnQi CMS template?

As an experienced CMS website operations manager for a leading security company, I know that high-quality content and convenient user experience are the key to attracting and retaining users.Tags (Tag) serve as an important dimension for content organization, not only helping users quickly find the content they are interested in, but also an indispensable part of internal link optimization and SEO strategy.

2025-11-06

How to use the `categoryDetail` tag to get category details in the AnQi CMS template?

Hello, I am your familiar old friend, a website operator who has been dealing with AnQiCMS for a long time.In daily content management and website optimization work, flexibly using AnQiCMS template tags is the key to improving efficiency and user experience.Today, let's delve deeply into a very practical tag: `categoryDetail`, and see how it helps us obtain detailed category information in the AnQiCMS template.

2025-11-06

How to use the `archiveList` tag in AnQi CMS template to call the document list?

As an expert who has been deeply involved in the field of CMS content operation for a long time, I fully understand the importance of a flexible and efficient template tag for website content display.Among them, the `archiveList` tag is undoubtedly the core tool for calling document lists in the Anqi CMS template.It can not only help us accurately filter and display various types of document content, but also combine multiple parameters to meet the diverse needs of content presentation, thus providing readers with a high-quality browsing experience.

2025-11-06

What is the role of the `safe` filter in the AnQi CMS template and when should it be used?

As a professional deeply familiar with the operation of Anqing CMS, I know the importance of template security and the correct presentation of content for a website.In the Anqi CMS template system, the `safe` filter plays a key role, concerning the security and display effect of the website. ### Automatic Escaping Mechanism of AnQiCMS Template AnQiCMS template system draws on the syntax characteristics of the Django template engine, one of its core design philosophies is security.

2025-11-06

How to use `truncatechars` and `truncatewords` in Anqi CMS template?

As a website operator who is well-versed in the operation of AnQiCMS, I deeply understand the subtleties of content presentation.How to elegantly handle the display of text content when building an engaging and user-friendly website experience.AnQi CMS, with its flexible class Django template engine, provides us with powerful content control capabilities, among which the text truncation feature is a commonly used tool for optimizing page layout and improving reading experience.

2025-11-06

How to use `join` and `split` filters to handle strings and arrays in AnQi CMS template?

As an experienced CMS website operation person in Anqi, I am well aware of the importance of flexible data handling in content management and display.The AnQi CMS template engine provides a rich set of filters to help us achieve this goal, among which the `join` and `split` filters are particularly powerful in handling string and array data, allowing our content display to be more dynamic and accurate.

2025-11-06

How to configure and display the `hreflang` tag in the Anqi CMS template?

As a website operator who deeply understands the operation of Anqi CMS, I am very clear about the importance of multilingual websites in today's global market and how to enhance the international visibility of the website through refined SEO strategies, such as the `hreflang` tag.The flexibility of AnQi CMS in multilingual support and template customization provides a solid foundation for us to achieve these goals.

2025-11-06