How to use `stampToDate` to format the creation time of associated documents in `tagDataList`?

Calendar 👁️ 67

As an experienced website operations expert, I fully understand the importance of flexible data display and user experience.The AnQi CMS provides many conveniences for content operation with its powerful customization capabilities.Today, let's delve into a very practical skill in daily content presentation: how totagDataListIn, beautifully format the creation time of the associated document.

Timestamp in AnQi CMS template: why do you need to format it?

In Anqi CMS, whether it is articles, products, or other content models, their creation time (CreatedTimeAnd update time(UpdatedTimeDates such as these are usually stored in the database in the form of Unix timestamps (Timestamp). This format is efficient and easy to handle for computers, but a string like1678886400Such numbers are meaningless.

As website operators, our goal is to provide clear and readable information.Convert these original timestamps to user-friendly date formats such as “March 15, 2023”, “10:30 AM yesterday”, or “Mar 15, 2023”, which can not only enhance the professionalism of the website but also improve the reading experience of users.

tagDataListA powerful tool for linking documents.

In the template design of AnQi CMS,tagDataListTags are a very practical tool, allowing us to retrieve and display lists of associated documents based on specific tags (Tag).For example, we may need to display all articles with the 'SEO optimization' tag on a page, or list all products related to 'new product launch'.

tagDataListWorks in a very intuitive way. It returns an array containing document objects, and we can access them throughforLoop to traverse these documents. Each document object (usually nameditem) contains various properties of the document, such asId/Title/Link/Description, of course, including the one we are concerned aboutCreatedTime.

Basic usage is as follows:

{% tagDataList archives with tagId="1" %}
    {% for item in archives %}
        <p>{{ item.Title }} - 创建时间:{{ item.CreatedTime }}</p>
    {% endfor %}
{% endtagDataList %}

If not processed{{ item.CreatedTime }}The output here is that cold, cold Unix timestamp.

stampToDate: The magic wand of time formatting

To transform these timestamps into a readable date format, Anqi CMS provides a very convenient built-in tag function:stampToDateThis function is designed specifically for timestamp formatting, and its usage is also very simple and clear.

stampToDateThe function requires two parameters:

  1. Timestamp (Timestamp)This is the original Unix timestamp you need to format. IntagDataListthe loop, it is usuallyitem.CreatedTime.
  2. Format String (Format String)This is a string defining the output date format. It should be noted that AnQi CMS is developed based on Go language, so this format string follows the Go language'slayoutStandard, that is, using oneFixed reference timeto define the format, rather than using placeholders like PHP or JavaScript (such asY-m-d)

The reference time in Go language is:2006-01-02 15:04:05This means, if you want to display the year, you write2006; to display the month, you write01; to display the date, you write02and so on.

Practice exercise: to transformtagDataListthe creation time into a magnificent transformation

Now, let's taketagDataListandstampToDateCombine them and see how to apply them in actual templates.

Assuming we have a TagID of1label, we need to list all associated document titles and their creation dates, displayed in the format of "Year-Month-Day Time:Minute":

{% tagDataList archives with tagId="1" %}
    {% for item in archives %}
        <div class="document-item">
            <h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
            <p>
                发布于:
                {{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}
                <span>浏览量:{{ item.Views }}</span>
            </p>
            <p>{{ item.Description }}</p>
        </div>
    {% else %}
        <p>当前标签下暂无关联文档。</p>
    {% endfor %}
{% endtagDataList %}

In the code above,item.CreatedTimePassed as the first parameterstampToDatewhile"2006-01-02 15:04"It acts as a format string, telling the system the date format we want to output.

Output example:

发布于:2023-03-15 10:30

Custom format, do as you wish

The date formatting method of the Go language may seem special at first glance, but once you master its principles, you can achieve extremely flexible custom formats. Here are some common formatting examples that can help you generalize from one to another:

  • Show only the year and month: {{ stampToDate(item.CreatedTime, "2006年01月") }}
    • output:2023年03月
  • Show English month and date: {{ stampToDate(item.CreatedTime, "Jan 02, 2006") }}
    • output:Mar 15, 2023
  • Show the full name of the weekday: {{ stampToDate(item.CreatedTime, "Monday, 2006年01月02日") }}
    • output:Wednesday, 2023年03月15日
  • Show AM/PM: {{ stampToDate(item.CreatedTime, "2006-01-02 03:04 PM") }}
    • output:2023-03-15 10:30 AM(NotePMCapitalize,03:04For 12-hour format)
  • Show short date: {{ stampToDate(item.CreatedTime, "01/02/06") }}
    • output:03/15/23

By these examples, you can freely combine the most appropriate date format based on the website's UI/UX design and the reading habits of the target audience.

Insights from content operation.

Precise and user-friendly time display is an indispensable part of high-quality content operation.It is not just a technical implementation, but also has a direct impact on the users' trust in website information and their dwell time.Whether it is news updates, blog articles, or product releases, clear publication or update times can help users quickly obtain key information and enhance the overall browsing experience.Provided by AnQi CMSstampToDateFunction, making everything simple and efficient.

Summary

MastertagDataListandstampToDateThe combination of use, is one of the basic skills for security CMS content operators.By explaining and providing examples in this article, I believe you can easily convert the original timestamp into various elegant and readable date formats in the AnQiCMS template, thereby adding luster to your website content.


Frequently Asked Questions (FAQ)

1.stampToDateWhy is the format string in the function so special, not common?Y-m-d?

This is because Anqie CMS is developed based on Go language, and its template engine follows the standard of Go language when processing date formats. The date formatting of Go language is based on a "reference time", namely2006-01-02 15:04:05.999999999 -0700 MSTEach number or letter you write in the format string corresponds to a specific component of this reference time (for example,2006represents the year,01Represents the month). Just write according to the reference time, and the system will automatically identify and output the corresponding time information. Although it may be a bit strange at first contact, it is very precise and flexible.

2. BesidestagDataListCan I also use it in other tags?stampToDateCome format the time?

Of course, I can. All returned documents in AnqiCMS (such asarchiveList/archiveDetail), categories (such ascategoryList/categoryDetail), or single pages (such aspageList/pageDetail) tags, if their internal data structure containsCreatedTimeorUpdatedTimeThis timestamp field can be usedstampToDateformatted by the function. The usage is the same as intagDataList, just replaceitem.CreatedTimewith the timestamp field corresponding to the label loop variable.

3. If I find that the creation time in the template is displayed directly as a long string of numbers (like1678886400), instead of a formatted date, how should I troubleshoot the issue?

This usually meansstampToDatethe function does not

Related articles

Is there an easy way to check if the input timestamp of `stampToDate` is valid in the AnQi CMS template?

As an experienced website operation expert, I am well aware that in a content management system like AnQiCMS, the accuracy and display format of timestamps are crucial for user experience and data presentation.`stampToDate` this powerful label function is undoubtedly a good helper for us to process time information in the template.However, like any tool, it also requires us to use and understand its input requirements correctly.Today, let's delve deeply into a problem that everyone may encounter in the development of Anqi CMS templates: **'In the Anqi CMS template

2025-11-07

How to ensure that the time zone is displayed as local time instead of UTC time when the `stampToDate` label formats time?

AnQiCMS (AnQiCMS) is an enterprise-level content management system developed based on the Go language, whose powerful template engine enables flexible and diverse content display.In daily content operations, the formatted display of time is a common need, and the `stampToDate` tag is exactly for this purpose.It can convert Unix timestamps into the familiar date and time format.However, many operators may encounter a confusion: why does the time formatted with `stampToDate` sometimes display as UTC time

2025-11-07

How to format output with `stampToDate` and then define a variable with `with` tag for reuse?

Dear Anqi CMS operation partners, hello! As an expert who deeply understands the integration of content operation and technology, I know the value of an efficient and flexible content management system for our daily work.AnQi CMS, with its high-performance architecture in Go language and Django-style template engine, undoubtedly provides us with powerful content display capabilities.Today, let's delve into a common and practical little trick in template design: how to cleverly define variables using the `with` tag after formatting output time with `stampToDate`

2025-11-07

Can the `stampToDate` label handle the millisecond precision of Unix timestamps?

In a content management system, the accurate display of time is crucial, especially when dealing with user behavior, data logs, or the release of specific events.AnQiCMS as a powerful content management system based on the Go programming language provides rich template tags to meet various content display needs, among which the `stampToDate` tag is a powerful tool for formatting timestamps.However, whether this tag can handle the millisecond level precision of Unix timestamps is a concern for many operators and developers.We can see from the official documentation of AnQiCMS

2025-11-07

How to concatenate the formatted date of the `stampToDate` tag with other text content to form a complete display message?

As an experienced website operation expert, I fully understand that how to flexibly display information is crucial for improving user experience and meeting operation requirements.AnQiCMS (AnQiCMS) is an efficient and easy-to-use content management system that provides powerful template tag functions, among which the `stampToDate` tag is a tool to process timestamps and format them into readable date strings.

2025-11-07

In the AnQi CMS template, can the `stampToDate` function display relative time such as 'X days ago' or 'X hours ago'?

As an experienced website operations expert, I know that flexible time display in content management systems is crucial for improving user experience and content timeliness.Especially displays such relative time as "X days ago", "X hours ago", which allows readers to understand the age of the content at a glance, thus better deciding whether to delve deeper into reading.Today, let's delve into whether the `stampToDate` tag built into the Anqi CMS template can achieve this relative time display, and how we should go about implementing it.--- ## AnQi CMS template in

2025-11-07

`CreatedTime` as a 10-digit timestamp, do you need to multiply it by 1000 before using `stampToDate`?

The mystery of timestamp conversion in AnQi CMS: As an experienced website operator and deep user of AnQi CMS, I know how common and crucial the handling of time data is in daily content management and template development.Especially when using a high-efficiency system like the Anqi CMS built with Go language, understanding and correct use of template tags are particularly important. Recently

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