In the `tag-stampToDate.md` example, how is the `publishStamp` variable defined, and can it be used in practice?

Calendar 👁️ 70

As an experienced website operation expert, I am well aware of the importance of content timeliness and display methods for user experience and SEO optimization in my daily work.AnQiCMS (AnQiCMS) takes advantage of its flexible template engine and rich tag system, providing us with great convenience.Today, let's delve into a topic that often comes up in template development:tag-stampToDate.mdIn the example,publishStampHow is a variable defined, can it be used in practice?

RevelationpublishStampThe definition of the variable and its real origin

When we first sawtag-stampToDate.mdExample code in the document{% set publishStamp = 1609470335 %}When, one might wonder: thispublishStampIs the variable system built-in? What does it represent?

Actually, in this specific example,publishStampIt is not a globally defined variable of an Anqi CMS system, but a variable inside the templateTemporary assignment.{% set ... %}Is an AnQi CMS template engine (based on Django-like syntax in GoLang) used to declare and assign variables at runtime in the template. This means,publishStampThis is just a placeholder to demonstratestampToDateThe usage of tags. It is assigned a specific 10-digit integer value, that is, the Unix timestamp1609470335.

Where do we usually get and format the timestamp in the actual operation of the Anqi CMS website?They mainly come from your website content, such as the publication time, update time, etc.The AnQi CMS will store these date information asUnix timestamp.

For example, intag-/anqiapi-archive/142.htmlIn the document we can clearly see:

  • Document add timeCreatedTime: This is a timestamp, which needs to be used when calling the template{{stampToDate(item.CreatedTime, "2006-01-02")}}to format.
  • Document Update TimeUpdatedTime: This is also a timestamp, with the same processing method asCreatedTimeSimilar.

When you edit an article in the background, the "publish time" field you fill in (such as2006-01-02 15:04:05This is a human-readable format) After being saved to the database, it will be converted into a 10-digit Unix timestamp by the internal conversion of the safe CMS. That isarchive.CreatedTimeandarchive.UpdatedTimeVariables can be directly used in the template asstampToDatethe reason for using tag parameters.

Therefore, in summary, the variables in thepublishStampexample are 'hypothetical' variables that help us understandstampToDateThe mechanism; in actual application, we will use the real timestamp obtained from the CMS content (such asarchive.CreatedTime) to replace it.

stampToDate: A flexible tool for timestamp conversion

Since we know the source of the timestamp, the next thing we need to understand is how to convert these original 10-digit numeric timestamps into user-friendly date formats, which isstampToDatethe responsibility of the tag.

stampToDateThe usage is very intuitive:{{stampToDate(时间戳, "格式")}}It takes two parameters:

  1. timestampIt must be a 10-digit integer representing the number of seconds since the Unix epoch (January 1, 1970, 00:00:00 UTC).
  2. FormatThis is a string that defines how you want the date and time to be displayed.It should be especially noted that the date format of Anqi CMS follows the specific format specification of the Go language.This means you need to use the predefined reference date in Go language2006-01-02 15:04:05.999999999 -0700 MSTBuild your format string. For example:
    • "2006年01月02日"Will be formatted as2021年06月30日
    • "2006-01-02"Will be formatted as2021-06-30
    • "15:04:05"Will be formatted as12:30:00(depending on the specific timestamp)
    • "2006/01/02 15:04"Will be formatted as2021/06/30 12:30

This formatting flexibility allows us to dynamically adjust the display of the date according to the style of the website, the reading habits of users in different regions, and even the needs of multilingual sites, without modifying the underlying data.

Actual application in AnQiCMS template

UnderstoodpublishStampthe background andstampToDateThe usage, and we can show our skills in the actual AnQi CMS template. The most common application scenarios are displaying the publication or update time of content in article lists or detail pages.

Assuming we are developing a template for an article detail page, we need to display the title, content, and publication date of the article.archiveDetailTags can help us get detailed information about the current article, includingCreatedTimefield.

The following is a specific template code snippet that demonstrates how to obtain the creation time of an article and format it as 'Year-Month-Day Hour:Minute':

<article>
    <h1>{{ archive.Title }}</h1> {# 直接访问 archive 变量获取标题 #}
    <div class="article-meta">
        发布时间:<span>{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04") }}</span>
        浏览量:<span>{{ archive.Views }}</span>
    </div>
    <div class="article-content">
        {{ archive.Content|safe }} {# 内容通常需要用 safe 过滤器以避免HTML转义 #}
    </div>
</article>

In this example:

  1. archiveIt is composed ofarchiveDetailLabel (or the current article object provided in thearchiveListloop).
  2. archive.CreatedTimeDirectly provided the article's creation timestamp.
  3. stampToDateThe label receives this timestamp and uses2006-01-02 15:04Translate the format string.

In this way, regardless of how the publication time of the background articles is stored, the front-end can present it to the visitor in a unified and clear format, greatly enhancing the readability and professionalism of the content.

Summary

In AnQi CMSpublishStampAn example variable, its core lies in guiding us to understandstampToDateThe function of the tag: Converts a 10-digit Unix timestamp to a readable date format. In actual content operations, we usually get content variables (such asarchive.CreatedTimeorarchive.UpdatedTime) Retrieve these timestamps and use the flexible Go language date format string to meet various time display requirements.Mastering this skill not only makes your website content more timely, but also effectively improves the user experience.


Frequently Asked Questions (FAQ)

1.stampToDateWhat date formats does the label support? How can I find the format I need?

stampToDateTags support all time formats in Go language. The key to understanding Go language time formats is to remember a special reference date:2006-01-02 15:04:05.999999999 -0700 MSTYou need to use the elements of this reference date to build the format you want.For example, if you want to display 'October 26, 2023, Thursday', you can try to construct a format string"2006年01月02日 星期一". The official Go language documentation provides detailed formatting examples, or you can also test it with an online Go date formatting tool.

2. I can directly use it in the templatearchive.CreatedTimeDo you want to display the time? Why do you needstampToDate?

If you output directly in the template{{ archive.CreatedTime }}, you will see a 10-digit number (for example1609470335This is the original form of Unix timestamp, not convenient for users to read.stampToDateThe label's role is to convert this original timestamp numberParse and formatMake the date-time string commonly seen in our daily life more readable. Therefore,

Related articles

How to ensure that `stampToDate` outputs a consistent date format on different server operating systems (such as Linux/Windows)?

In website operation, the display of content publishing time is often one of the details that users pay attention to. Ensuring that these dates and times are presented in a consistent format across different server environments (such as the familiar Linux and Windows) is an important factor in improving user experience and maintaining website professionalism.As an experienced operator of AnQi CMS, I am well aware of its powerful capabilities based on the Go language, especially the unique advantages of the template tag `stampToDate` in dealing with such issues.Today, let's delve deeper

2025-11-07

Does the `stampToDate` tag have different formatting capabilities between different versions of Anqi CMS?

As an experienced website operations expert, I am deeply familiar with the various functions and content operation strategies of AnQi CMS, and I am happy to analyze the time formatting capability of the `stampToDate` tag across different versions of AnQi CMS.This tag plays an important role in daily content display, especially for websites that need to finely control the display format of time, where stability and functional characteristics are of great concern to operators.### AnQi CMS `stampToDate` tag time formatting capability

2025-11-07

How to print the original input timestamp value of `stampToDate` when debugging the AnQi CMS template?

As an experienced website operations expert, I am well aware that AnQiCMS (AnQiCMS) brings great convenience to small and medium-sized enterprises and content operation teams with its efficient Go language architecture and rich features.System design focuses on practicality and scalability, especially in terms of template customization and content presentation, providing us with great freedom.In daily content operation and maintenance, template debugging is an inevitable part, and correctly obtaining and understanding the original data of variables in the template is crucial for efficient troubleshooting. Today

2025-11-07

How to use `stampToDate` to format a timestamp into a time format that includes AM/PM indicators?

As an experienced website operations expert, I am well aware that the way website content is presented is crucial for user experience and the efficiency of information transmission.Especially when dealing with basic information such as time, if it can be formatted in a way that is accustomed to the user (for example, including the 12-hour AM/PM format), it will greatly enhance the professionalism and user-friendliness of the website.AnQiCMS (AnQiCMS) is a powerful and detail-oriented content management system that naturally also provides flexible time formatting tools. Today

2025-11-07

How to batch update the date format string of all `stampToDate` tags in the Anqi CMS template?

How to efficiently batch update the date format string of the `stampToDate` tag in AnQi CMS template?Practical Guide As an experienced website operations expert, I am well aware of the importance of the timeliness and presentation of website content for user experience and brand image.In such an efficient and flexible system as Anqi CMS, we often use `stampToDate` such date formatting labels to display the content publication or update time.

2025-11-07

Can `stampToDate` format a date to `3:04 PM` in 12-hour format?

## AnQi CMS `stampToDate` tag: Flexibly display 12-hour time, from 3:04 PM to more possibilities In the daily operation of AnQi CMS, we fully understand that every detail of content presentation is crucial, especially the display of time information.Whether it is the release time of the article, the deadline of the event, or the update time of the product, a clear and user-friendly date and time format can greatly enhance the user experience.Recently, a friend mentioned a common question: "The "stampToDate" method of Anqi CMS"

2025-11-07

How does the performance of `stampToDate` in Anqi CMS template look, will it affect the page loading speed?

## The `stampToDate` in Anqi CMS template: Will it slow down the page loading speed?As an experienced website operations expert, I am well aware that page loading speed is crucial for user experience and search engine optimization.When a template includes some data processing tags, many operators will inevitably have doubts: will this function affect website performance?Today, let's talk about a commonly used and practical tool in Anqi CMS template - the `stampToDate` tag, and delve into its performance in page loading speed

2025-11-07

How to use `stampToDate` to output the countdown of 'X days until an event' in the template?

## Tips for Anqi CMS Template: Creating an Eye-Catching Countdown Effect for "X Days Until an Event" In today's fast-paced online environment, effective content operation is inseparable from dynamic interaction with users.A well-designed website that not only provides rich information but also enhances user engagement and conversion rates through some clever dynamic elements, such as countdowns.No matter if it's a new product launch, event preview, or an important milestone reminder, a striking countdown can inject vitality into your website and create a sense of urgency.

2025-11-07