In AnQi CMS, how does the `stampToDate` tag convert a 10-digit timestamp to a common date format?

Calendar 👁️ 64

Time Wizard: Anqi CMSstampToDateHow to easily handle 10-digit timestamps with tags

In the world of content operation, the way time is presented often directly affects users' understanding and perception of the content.A clear and easy-to-read date format that allows users to quickly obtain key information while browsing articles, products, or comments, thereby enhancing the overall browsing experience.However, at the database and system level, time is often represented by a string of "mysterious" numbers - a 10-digit timestamp (Unix timestamp) - that exists.This is efficient and standardized for machines, but it is like a book of heaven for ordinary users.

AnQi CMS, as an enterprise-level content management system developed based on the Go language, deeply understands this. In order to enable content operators to easily handle these timestamps and convert them into a warm and easy-to-understand date format, AnQi CMS provides a powerful and flexible template tag:stampToDate. It's like a time wizard, able to transform those boring 10-digit numbers into the various date and time expressions you want.

stampToDate: Convert machine time to human-readable time

Imagine when you need to display the publish time in a list of website articles or mark the update date on a product detail page, and you see something like1609470335When this string of numbers is used instead of stampToDateTags are exactly born to solve this pain point.

Its basic usage is very intuitive:{{stampToDate(时间戳, "格式")}}

The 'timestamp' here is what we call the 10-digit number, usually in the documents of Anqi CMS (such asCreatedTimeorUpdatedTimeFields are stored in this form. And "format", it is the key to the magic of the tag. It follows the unique and highly flexible time formatting rules of the Go language.stampToDate标签发挥魔法的关键所在。它遵循Go语言独特且高度灵活的时间格式化规则。

Unveiling Go language's time formatting: the unique "reference time"

May be used by some other content management systemsY-m-dorH:i:sThese symbols are different, the date formatting in Go language uses a unique "reference time"-2006-01-02 15:04:05. This does not mean that the timestamp will be formatted as 2006 or 15 o'clock, but rather with each number in this datePositionas the reference for formatting.

For example, if you want to convert a 10-digit timestamp1609470335(which represents2021 January 1 07:05:35 UTCFormat into different common date formats, you can do this:

  • Display only year, month, and day (separated by hyphens): {{stampToDate(1609470335, "2006-01-02")}}It will be displayed as2021-01-01
  • Display only hours, minutes, and seconds: {{stampToDate(1609470335, "15:04:05")}}It will be displayed as07:05:35
  • Display the full year, month, day, hours, minutes, and seconds: {{stampToDate(1609470335, "2006-01-02 15:04:05")}}It will be displayed as2021-01-01 07:05:35
  • Custom Chinese format: {{stampToDate(1609470335, "2006年01月02日 15时04分")}}It will be displayed as2021年01月01日 07时05分
  • Change the date order (e.g., day/month/year): {{stampToDate(1609470335, "02/01/2006")}}It will be displayed as01/01/2021

This "reference time" setting makes formatting extremely flexible. You just need to match the output format you expect,2006-01-02 15:04:05This refers to the time, write the corresponding number and separator. For example, if you want to display the abbreviation of the month, you can refer to the Go language rules, usingJanto replace01, like this{{stampToDate(1609470335, "02 Jan 2006")}}it will be displayed as01 Jan 2021.

Practice in the Anqi CMS template.stampToDate

In the actual development of Anqi CMS templates,stampToDateTags are usually witharchiveList/archiveDetailUse these tags together to format timestamp fields retrieved from the database.

For example, on an article list page, you might use it to display the publication date of each article:

{% archiveList latestArticles with type="list" limit="5" %}
    {% for article in latestArticles %}
        <article>
            <h2><a href="{{ article.Link }}">{{ article.Title }}</a></h2>
            <p>发布于:{{ stampToDate(article.CreatedTime, "2006年01月02日") }}</p>
            <p>{{ article.Description }}</p>
        </article>
    {% endfor %}
{% endarchiveList %}

Or on the article detail page, display the update time of the article:

<article>
    <h1>{% archiveDetail with name="Title" %}</h1>
    <p>
        最后更新:{{ stampToDate(archive.UpdatedTime, "2006-01-02 15:04") }}
    </p>
    <div>
        {%- archiveDetail articleContent with name="Content" %}
        {{articleContent|safe}}
    </div>
</article>

No matter if you need an update log precise to the second or a concise release date,stampToDateThe labels can be adjusted with simple format parameters to meet all your needs.This has greatly improved the readability of the content and also made the overall presentation of the website more professional and friendly.The Anqi CMS is dedicated to providing such practical and efficient features, making content operations more skillful.


Frequently Asked Questions (FAQ)

1. The timestamp I got from the database is not 10 digits,stampToDateCan the tag still be used? stampToDateTags are designed for the standard 10-digit Unix timestamp.If your timestamp is 13 digits (millisecond level), you need to divide it by 1000 first to convert it to 10 digits, or handle it on the front end using JavaScript and other methods.Directly pass in a 13-digit timestampstampToDateMay get incorrect results.

2. Besides the examples in the article, what are some common date formatting references in the Go language? Where can I find more?The date formatting of Go language is very rich, including2006-01-02 15:04:05There are also many combinations, such as:

  • Mon Jan _2 15:04:05 MST 2006(Standard CST format, such as:周一 1月 01 07:05:35 UTC 2021)
  • 2006-01-02T15:04:05Z07:00(ISO 8601 standard format)
  • 3:04PM(AM/PM time format) You can find the detailed instructions for 'format timestamp tag' in the 'Template Creation' document of Anqi CMS (i.e.tag-stampToDate.md), among more detailed formatting examples.

**3.

Related articles

How to prevent whitespace issues during the development stage of AnQiCMS templates?

How to elegantly prevent whitespace issues in AnQiCMS template development?In the era of refined website operation, every detail may affect user experience and search engine performance.For users and developers of AnQiCMS (AnQi CMS) who pursue efficiency, security, and customization, the quality of the HTML code output by the template is crucial.AnQi CMS, this enterprise-level content management system based on Go language has won the favor of many users with its powerful functions and flexible template engine.

2025-11-07

In AnQiCMS template, what is the potential relationship between `forloop.Counter` and the blank control?

## AnQiCMS template of `forloop.Counter` and blank control: Refine your list output As a senior website operations expert, I know that in a content management system, the flexibility of templates and the tidiness of output are crucial for the long-term maintenance of websites and search engine optimization (SEO).AnQiCMS with its efficient architecture based on the Go language and support for Django-like template engine syntax, provides us with powerful content display capabilities.

2025-11-07

AnQiCMS template, what are the usage scenarios of `{%- elif -%}`?

As an experienced website operations expert, I am well aware of the importance of the flexibility of content management system templates for website operations efficiency and user experience in my daily work.AnQiCMS (AnQiCMS) provides us with great convenience with its efficient architecture based on the Go language and Django-like template engine syntax.During the template creation process, understanding and skillfully using various tags is the foundation, and logical judgment tags like `{%- elif -%}` are crucial for implementing dynamic content display and enhancing user experience.

2025-11-07

Does the `lorem` tag of the AnQiCMS template generate text with additional blank lines?

In AnQiCMS (AnQiCMS) template development, we often use various tags to quickly build pages, among which the `lorem` tag is favored by front-end developers for its ability to generate random placeholder text.However, whether the text generated by the `lorem` tag includes additional blank lines is indeed a question worth delving into, especially for operators who strive for pixel-perfect and tidy code.

2025-11-07

How to use the `stampToDate` tag to display the publication date of each document on the article list page?

## Enabling content timeliness: The efficient way to display publication dates on the article list page of AnQi CMS In today's fast-paced digital world, the timeliness of content is crucial for the attractiveness of a website and the user experience.Whether it is news reports, technical articles, or product updates, clearly displaying the publication date can help readers quickly judge the value of the information and enhance the professionalism of the website.

2025-11-07

How to format `CreatedTime` obtained from the `archiveDetail` tag using `stampToDate` to the "YYYY-MM-DD" format?

## Unlock the AnQi CMS Time Magic: How to beautifully format `CreatedTime` to "YYYY-MM-DD" As an experienced website operations expert, I am well aware of the importance of content timeliness and display methods for user experience.In AnQiCMS (AnQiCMS) such a powerful content management system based on Go language, we can not only efficiently manage content, but also convert technical information into user-friendly display through flexible template tags.Today, let's talk about a common demand in operation

2025-11-07

In Anqi CMS template, the 'format' parameter of `stampToDate` should follow which time formatting standard of the Go language?

## The mystery of time formatting in `stampToDate` of AnQi CMS template: Unveiling the time standard in Go language As an experienced website operations expert, I know that the flexible display of timestamps in content management systems is crucial for the freshness of website information and user experience.AnQiCMS (AnQiCMS) relies on the powerful genes of the Go language, and inherits the unique elegance and efficiency of the Go language in template processing.Today, let's delve deeply into a commonly used and powerful time processing function in the Anqi CMS template —— `stampToDate`

2025-11-07

How to use `stampToDate` to format the `UpdatedTime` of the document into a complete date and time that includes hours, minutes, and seconds?

As an experienced website operation expert, I am well aware that the details of content presentation are crucial for user experience and information delivery.AnQiCMS (AnQiCMS) with its flexible and powerful template engine, provides us with great freedom.Today, let's delve deeply into a common and practical need in content operation: how to use the `stampToDate` function to format the `UpdatedTime` of a document into a complete date and time that includes hours, minutes, and seconds.

2025-11-07