How to use the `stampToDate` tag to format timestamps into a friendly date format to display content publication time?

Calendar 👁️ 73

The time of content release is an important component of conveying information to visitors in the process of website operation.A clear and readable date format can not only improve user experience but also make the website look more professional and timely.In AnQiCMS, the content publish time is usually stored in the form of a series of numbers (i.e., a timestamp).How can we convert these numbers into the familiar 'year-month-date' or 'month/day time:minute' formats that we are accustomed to?stampToDate.

Understand the timestamp in AnQiCMS

In the template development of AnQiCMS, we often encounter things likeitem.CreatedTime(Content creation time) orarchive.UpdatedTime(Content update time) such variables. Their values are usually a 10-digit Unix timestamp, for example1609470335.This original timestamp is very convenient for machine processing, but it is not very intuitive for human reading.In order to enhance the reading experience of the website content, we need a method to translate these timestamps into a more easily understandable date and time format.

IntroductionstampToDateTag

At this time,stampToDateThe tag comes into play. Its basic usage is very intuitive, following the common syntax of the AnQiCMS template engine:

{{stampToDate(时间戳, "格式")}}

This tag accepts two main parameters:

  1. Timestamp:A 10-digit Unix timestamp that is usually obtained fromarchive/itemsuch objects.CreatedTimeorUpdatedTimefield.
  2. Format:A string that defines the date and time display format you want.

Master the time formatting rules of Go language

The "format" parameter is to understand and master herestampToDateThe key tag. AnQiCMS template engine uses Go language at the bottom, so the time format definition also follows the unique way of Go language. Unlike the commonYYYY-MM-DDThe format of the equal sign placeholder is different, Go language uses a specific oneReference timeTo define the various parts of the date and time. This reference time is:

January 2, 2006 3:04:05 PM(The time zone is usually MST or UTC-0700)

The principle is: you want which part of the date and time to be displayed in what form, use the corresponding number or character of this reference time to represent it. For example:

  • Year:Use2006Represent a four-digit year.
  • Month:Use01Represent a two-digit month (with leading zeros if necessary), using1Represent a month without leading zeros.
  • Day:Use

Related articles

How to use `if` and `for` tags to implement conditional display and loop display of content in AnQiCMS templates?

In the AnQi CMS template world, flexibly controlling the display of content is the key to creating an engaging website.Whether it is to display different information based on specific conditions or to efficiently display a large amount of data, the `if` and `for` tags are indispensable tools for us.AnQiCMS's template engine adopts the syntax of Django, making these operations intuitive and powerful.### Understanding the `if` tag: Implementing conditional display of content The core function of the `if` tag is to decide whether to display a part of the content based on the conditions you set

2025-11-08

How `tdk` tags can dynamically generate and optimize SEO-related Title, Keywords, and Description for each page?

In modern website operation, the importance of Search Engine Optimization (SEO) is self-evident, and the page title (Title), keywords (Keywords), and description (Description), which we commonly refer to as TDK, are the "business card" of the website content on the Search Engine Results Page (SERP).They not only directly affect the click-through rate of the page, but are also key factors for search engines to understand the content of the page and rank it.AnQiCMS (AnQiCMS) fully understands the significance of TDK for SEO, and therefore in the system design

2025-11-08

How to dynamically fetch and display the global settings and contact information of the website using the `system` and `contact` tags?

In AnQi CMS, the global settings and contact information are the basic information that constitutes the important facade of the website.This information must be displayed accurately to visitors, and more importantly, it should be able to be updated and managed flexibly and conveniently without frequent modifications to the template code.AnQi CMS provides these two powerful tags, `system` and `contact`, allowing website operators to easily achieve dynamic acquisition and display of this information.

2025-11-08

How does the `pagination` tag add and control pagination display for document lists to enhance user experience?

When building a website, as the amount of content grows, the document list page becomes long, which not only affects the page loading speed but also makes it difficult for visitors to find the information they need efficiently.At this time, adding pagination to the document list becomes a key factor in improving user experience.AnQiCMS provides a powerful `pagination` tag, combined with the document list tag `archiveList`, it can easily achieve this goal, making your website content display more professional and more user-friendly.

2025-11-08

How to define temporary variables with the `with` tag in a template to better control content display logic?

When developing website templates in AnQiCMS, we often need to handle various data and decide the display mode of the content according to these data.With the complexity of website functions, the logic in the templates sometimes becomes difficult to understand and maintain.At this point, mastering some advanced template tag usage is particularly important, and the `with` tag is one of the practical tools that can significantly improve the readability and control of the template.### The `with` tag: A tool for defining temporary variables in templates The `with` tag allows us to define temporary variables within a specific area of the template

2025-11-08

How to correctly insert mathematical formulas and flowcharts in a Markdown editor and ensure they display normally on the web?

In content creation, especially in fields involving technology, science, or complex concepts, we often need to insert mathematical formulas or draw flowcharts to assist in explanation.The Markdown editor of AnQiCMS (AnQiCMS) has provided us with great convenience, allowing these complex elements to be input in a concise text form and presented elegantly on the web.How should we operate specifically to ensure that the content is displayed correctly?Firstly, make sure that your safety CMS system has enabled the Markdown editor.

2025-11-08

How does the search engine link push feature help new documents be indexed and displayed in search results quickly?

On the day of content release, how can your meticulously crafted website content be quickly discovered and indexed by search engines, which is a focus for every content operator.A newly released article or product page, if it can appear quickly in the search results, it will undoubtedly seize the initiative and bring valuable early traffic.AnQiCMS (AnQiCMS) fully understands this need and has specially provided a search engine link push feature to help your new document reach the search engine as quickly as possible, thereby speeding up indexing and display.Why is it important to be indexed quickly?

2025-11-08

How to configure custom rewrite rules to create more SEO-friendly content URLs?

The importance of URL structure in website operation is self-evident.A clear, concise, and keyword-rich URL not only improves user experience but also makes it easier for users to remember and share content, and can significantly optimize the crawling and ranking effects of search engines.Aqicms is well aware of this, therefore it provides a flexible and powerful pseudo-static rule configuration function to help users create more SEO-friendly content URL displays.What is the pseudo-static URL and its importance?So-called pseudo-static is not a real static page, but refers to URL rewriting technology through the server

2025-11-08