How to format the display of the release and update time of AnQiCMS documents?

Calendar 👁️ 62

As an experienced website operations expert, I am well aware that the accuracy and readability of time in content display are crucial for user experience and Search Engine Optimization (SEO).AnQiCMS as an efficient and flexible content management system provides a very convenient way to control the display format of the article's publication and update time.This article will focus on how AnQiCMS formats and displays the publication and update time of documents, and will explain the secrets and practical skills in detail.


AnQi CMS: Flexibly control the sequence of articles, easily format the publication and update time

In today's increasingly rich digital content, the time of article publication and update is not only an important indicator of the life cycle of the content, but also a key element in conveying the timeliness and professionalism of the information to readers.A clear and standardized time display that can effectively improve user experience and help search engines better understand and index your content.AnQi CMS is well-versed in this, providing powerful and flexible template tags that allow us to easily format the publication and update times of documents.

Understand the time storage mechanism of AnQi CMS

Before delving into formatting methods, we first need to understand how AnQiCMS stores time. To ensure data processing efficiency and cross-platform compatibility, AnQiCMS usually stores the publication time of articles (CreatedTimeAnd update time(UpdatedTimeStored as(Unix timestamp.This is the number of seconds from 00:00:00 UTC on January 1, 1970 to the current time, existing in pure digital form, which is friendly to computers but difficult for humans to understand intuitively.Therefore, we need a conversion tool to convert these timestamps into the date and time format we are familiar with.

Core tool:stampToDateFormatted timestamp label

AnQiCMS provides a namedstampToDateThe template tag that is the key to solving the timestamp formatting problem.This tag can receive a Unix timestamp and convert it into a readable date and time string according to the format you specify.

stampToDateThe usage method of the tag is very intuitive:{{stampToDate(时间戳, "格式")}}

Here is the "timestamp" you need to convertCreatedTimeorUpdatedTimeVariable, and the "format" is the key to defining the final display effect

Mastering the Golang time format

stampToDateThe "format" parameter follows the unique time formatting rules of Golang (Go language). Unlike PHP or Java, it uses letter symbols such asY/m/dThe year, month, and day are represented differently, Golang uses oneFixed reference timeAs the formatting template, namely:

2006-01-02 15:04:05

This seemingly ordinary date and time string has a special meaning in Go:

  • 2006Represents the year (four digits)
  • 01Represents the month (two digits, with leading zeros if necessary)
  • 02Represent the date (two digits, leading zero if necessary)
  • 15Represent the hour (24-hour format, two digits, leading zero if necessary)
  • 04Represent the minutes (two digits, leading zero if necessary)
  • 05Represents seconds (two digits, leading zeros if necessary)

In addition, the Go language supports other formatting elements, such as:

  • MonRepresents the abbreviation of the day of the week (e.g., Mon, Tue)
  • MondayRepresent the full name of the week (e.g., Monday, Tuesday)
  • JanRepresent the abbreviation of the month (e.g., Jan, Feb)
  • JanuaryRepresent the full name of the month (such as: January, February)
  • PMorpmRepresent AM/PM identifier
  • MSTor-0700Represent time zone information

Understood this reference time, you can then combine any date and time format you want, like stacking blocks.

Some common formatting examples:

The format you want to display Go language format string Sample output
Complete date (Year-Month-Day) "2006-01-02" 2023-10-26
Complete date (Year/Month/Day) "2006/01/02" 2023/10/26
Chinese date "2006年01月02日" 2023年10月26日
Complete Date and Time (24-hour format) "2006-01-02 15:04:05" 2023-10-26 10:30:45
Complete Date and Time (12-hour format) "2006-01-02 03:04:05 PM" 2023-10-26 10:30:45 AM
Month and Date "01-02" 10-26
Day of the Week and Date "Mon, 02 Jan" Thu, 26 Oct

Formatted Time on Document Detail Page

In the document detail page (usually correspondingarchiveDetailto the data obtained from the tag), you can directly access the current document'sCreatedTimeandUpdatedTimefield.

Assuming your document variable is namedarchive:

{# 格式化显示文档发布时间 #}
<p>发布时间:{{stampToDate(archive.CreatedTime, "2006年01月02日 15:04")}}</p>

{# 格式化显示文档更新时间 #}
<p>最后更新:{{stampToDate(archive.UpdatedTime, "2006-01-02 15:04:05")}}</p>

{# 如果只显示日期,不显示时间 #}
<p>发表于:{{stampToDate(archive.CreatedTime, "2006-01-02")}}</p>

format the time in the document list page

When you use on the article list pagearchiveListWhen tags cycle through multiple articles, you can use loop variables (for exampleitem) to access the time field of each article.

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
        <article>
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <div class="meta">
                <span>发布:{{stampToDate(item.CreatedTime, "2006/01/02")}}</span>
                {% if item.CreatedTime != item.UpdatedTime %} {# 判断发布时间与更新时间是否一致,不一致才显示更新时间 #}
                    <span>更新:{{stampToDate(item.UpdatedTime, "2006/01/02 15:04")}}</span>
                {% endif %}
            </div>
            <p>{{item.Description}}</p>
        </article>
    {% endfor %}
{% endarchiveList %}

In this way, you can easily display the publication and update time of each article in the article list and choose different formats as needed.

Why is it important to display time accurately?

  1. Enhancing user experience: Readers can quickly tell the age of the article, which is crucial for news, technical articles, or any time-sensitive content.
  2. Enhance content trustworthiness: Clear update time indicates that the content provider is maintaining and updating information, which increases the reliability of the content.
  3. Optimize search engine rankings: Search engines consider the publication and update time when evaluating the relevance and freshness of web pages.Reasonably displaying this information helps search engines better understand your content, thereby potentially achieving better search rankings.

Summary

Anqi CMS passedstampToDateThe tag combines the time formatting rules of the Go language, providing website operators with powerful and flexible time display control capabilities.Whether it is the precise publication time down to the second or a concise update date, you can easily achieve it according to your design and operational needs.Master these skills and make your website content more timely, professional, and ultimately transform it into a better user experience and superior SEO performance.


Frequently Asked Questions (FAQ)

  1. Ask: The AnQiCMS document'sCreatedTimeandUpdatedTimeCan it be stored in a format other than Unix timestamp? Answer:Not allowed. AnQiCMS internally uses Unix timestamps to storeCreatedTimeandUpdatedTimeThis is for the efficiency of data processing and the uniformity of the system's internal storage. You don't need to care about its internal storage format, just throughstampToDateLabel it in the front-end template to display it in any format you need.

  2. **Question

Related articles

How to display multiple cover group images in a document detail page?

As an expert who deeply understands website operation, I know that high-quality, visually appealing content is the key to retaining users and enhancing the value of the website.AnQiCMS (AnQiCMS) is a powerful content management system that provides great flexibility in content presentation.Today, let's delve into a common need: how to cleverly loop multiple cover group images on the document detail page to make the content more expressive. --- ## Secure CMS: Delicate Presentation!A guide to displaying multiple cover group images in document detail pages In the era of content is king

2025-11-06

How does Anqi CMS display the cover image and thumbnail of the document?

As an experienced website operations expert, I know the importance of a high-quality cover image and a proper thumbnail for the attractiveness of the website, user experience, and even search engine optimization (SEO).AnQiCMS (AnQiCMS) deeply understands this, and its design in image processing and display is not only powerful in function but also takes into account the convenience of operation and flexibility of display. Let's delve into how Anqi CMS cleverly displays document cover images and thumbnails.

2025-11-06

How to set and call the recommended attribute (Flag) of the document in AnQiCMS?

## AnQiCMS High-efficiency Operation Manual: Mastering the Settings and Calls of Document Recommendation Attributes (Flag) As an experienced website operations expert, I am well aware that how to make your high-quality content stand out in the vast sea of digital content and accurately reach your target users is the key to success.AnQiCMS as a powerful content management system, its built-in "Flag" feature is a powerful tool to help content achieve fine-grained operation.It can not only help you flexibly organize and display content, but also effectively enhance the exposure and user perception of the content. Today

2025-11-06

How to call and display the views (Views) of Anqi CMS documents?

As an experienced website operations expert, I know that every data indicator contains a profound insight into the performance of website content and user behavior.In AnQiCMS (AnQiCMS) such an efficient and practical content management system, the flexible invocation and display of core data such as 'Document Views' is an indispensable ability for content operators.This not only helps us understand the content popularity intuitively, but is also an important basis for optimizing content strategy and improving user experience.

2025-11-06

How to obtain all the details of the category owned by the document details page?

How to retrieve all detailed information of the category owned by the document detail page of Anqi CMS?In website content operations, the document detail page is not just for displaying articles or products, it often needs to establish a connection with a broader content system, such as displaying detailed information about its category.This not only enhances the user experience, guides users to discover more related content, but also helps improve the internal link structure and SEO performance of the website.As an experienced website operation expert, I deeply understand the strength and flexibility of AnQiCMS (AnQiCMS) in dealing with such needs.

2025-11-06

How to call custom document fields (such as author, price) and display them in AnQi CMS?

AnQi CMS offers powerful content management capabilities with its excellent flexibility and customizability to website operators.In the daily operation of websites, we often encounter situations where standard fields (such as titles, content, and publication time) cannot fully meet the needs of specific content display.At this moment, custom document fields have become our powerful assistants, for example, adding "author" information to an article, or supplementing "price" attributes to a product, and so on.How can we flexibly call these custom fields and display them on the website page in Anqi CMS today?

2025-11-06

Unveiling AnQi CMS: How Markdown content is beautifully presented on your website?

AnQi CMS is an efficient content management system that knows well the pursuit of convenience by content creators.Markdown is a lightweight markup language that is favored by content editors for its concise, easy-to-learn, and clear formatting features.How can we ensure that the wonderful content you write in Markdown in Anqi CMS can be perfectly converted into browser-readable HTML and displayed on the front-end page without any loss?

2025-11-06

How to get the list of articles under a specified category in AnQiCMS?

## Easily retrieve the list of articles under a specified category in AnQiCMS As an experienced website operations expert, I fully understand the core value of a content management system (CMS) lies in its ability to organize and present content.Among many features, how to efficiently extract and display articles from a specific category is an indispensable part of the daily work of website operators.Today, let's delve deep into how AnQiCMS can help you achieve this goal, making technical details intuitive and easy to understand.

2025-11-06