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

Calendar 👁️ 70

As an experienced website operations expert, I know that how to flexibly display information in a content management system is crucial for improving user experience and meeting operational needs. AnQiCMS, as an efficient and easy-to-use content management system, provides powerful template tag functions, among whichstampToDateTags are a powerful tool for processing timestamps and formatting them into readable date strings.

Today, let's delve into how to make use ofstampToDateLabel, cleverly concatenate the formatted date with other text content on the page to form a complete and informative display information.


Make good use of AnQiCMSstampToDateLabel, create flexible date display information

In website operation, date and time information is everywhere, whether it is the publication time of articles, the last update time of content, or the deadline for user activities, a clear and friendly date display can greatly enhance the professionalism and user reading experience of website content. AnQi CMS fully understands this, providing us withstampToDateLabels make date formatting very simple.

However, simply formatting dates is not enough, we often need to combine this date information with fixed text, other variables, etc., to form a complete, contextually descriptive paragraph. For example, we want to displayPublished on October 27, 2023, views 1234 timesThis is not just the solitary 'October 27, 2023'. Next, let's take a look at how to achieve this flexible concatenation in Anqi CMS templates.

I.stampToDateBasic usage of tags review

First, let's briefly reviewstampToDateThe core function of the label. Its main role is to convert the timestamp stored in the database (usually a 10-digit integer) into a readable date and time format. The basic syntax is:

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

The key lies in the second parameter"格式". It follows the date formatting rules specific to the Go language, such as2006-01-02 15:04:05This reference time to define various display formats. For example:

  • "2006-01-02"It will be displayed as2023-10-27
  • "2006年01月02日"It will be displayed as2023年10月27日
  • "2006/01/02 15:04"It will be displayed as2023/10/27 10:30
  • "Mon, 02 Jan 2006 15:04:05 MST"It will be displayed asFri, 27 Oct 2023 10:30:00 CST

In AnQi CMS, we often get timestamp fields from document objects(archiveor from loops, such asitem)archive.CreatedTime(creation time) andarchive.UpdatedTime(update time).

{# 假设当前处于文档详情页,archive代表当前文档对象 #}
<p>文章发布时间:{{ stampToDate(archive.CreatedTime, "2006年01月02日") }}</p>
<p>最后更新:{{ stampToDate(archive.UpdatedTime, "2006-01-02 15:04:05") }}</p>

Two, the clever combination of dates and text content

MasteredstampToDateThe basis, we can start to concatenate it with other text content.In Anqi CMS's Django-like template engine, how many natural and smooth ways are there to concatenate text and variables.

1. Embed formatted dates directly in the text

The most direct way is to embed the formatted date label directly into a fixed text description. The template engine will parse it firststampToDateLabel, then concatenate the result with the adjacent text.

For example, we want to display "Published on [date]" on the article detail page:

<p>发布于 {{ stampToDate(archive.CreatedTime, "2006年01月02日") }}</p>
{# 页面将显示:发布于 2023年10月27日 #}

If you need to include more information, such as the article title and reading volume:

`twig

文章 <strong>《{{ archive.Title }}》</strong> 发布于 
<time datetime="{{ stampToDate(archive

Related articles

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

As an experienced website operations expert, I am well aware of the importance of flexible data display and user experience.AnQi CMS with its powerful customization capabilities provides many conveniences for content operations.Today, let's delve deeply into a very practical skill in daily content presentation: how to elegantly format the creation time of associated documents in `tagDataList`. ### Timestamp in AnQi CMS template: Why is formatting necessary?In Anqi CMS, whether it is articles, products, or other content models

2025-11-07

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

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

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