How to use `stampToDate` to format the timestamp to only display the "month-date" concise date?

Calendar 👁️ 64

In content operation, clear and intuitive date information is crucial.Whether it is the release date of a news article or a reminder of the deadline for an event, a concise and easy-to-understand date format can greatly improve the user experience.AnQi CMS is an efficient content management system that provides powerful template tag functions, allowing us to flexibly control content display.Today, let's delve into how to make full use of the powerful template tags of AnQi CMSstampToDateFormat the original timestamp cleverly to only display a concise "month-date".

Time processing art in Anqi CMS template

In Anqi CMS, the creation and update time of articles or products and other content is usually stored in the database in the form of a 10-digit Unix timestamp, for example1609470335. Such original timestamps are very convenient for system processing, but they are quite difficult for ordinary website visitors to understand and not very beautiful.To convert these cold numbers into user-friendly date formats, Anqi CMS providesstampToDateThis is the formatted timestamp label.

stampToDateThe basic usage of labels is very intuitive, it accepts two parameters: the first is the timestamp you want to format, and the second is the date-time format string you want to output. Its syntax is usually presented as:{{stampToDate(时间戳, "格式")}}.

It should be emphasized here that the format parameter's writing may be different from what you are accustomed to in other systems (such as PHP or JavaScript)Y-m-doryyyy-MM-ddThe placeholder pattern is different. Anqicms is developed based on Go language, its date formatting follows the Go language'stime.FormatStandard, which means it does not use abstract placeholders but defines the format with a fixed "reference time". This reference time is2006年01月02日15时04分05秒also commonly referred to by Go language developers asMon Jan 2 15:04:05 MST 2006.

Understand this is to use it flexiblystampToDateThe key: You should use this reference time to spell out what you want to display in the final output. For example, if you want to display a four-digit year, write2006If you want to display two-digit months, write01If you want to display a two-digit date, write02and so on.

Easily implement the concise date format "month-day"

Now, let's focus on the core goal of the article: how to format a timestamp to display only the 'month-day' concise date.

According to the reference time agreement of the Go language, to display two-digit months, we should use01; to display two-digit dates, we use02Therefore, if we want to display the date in the format "month-day", such as "06-30", then the corresponding format string should be"01-02".

Suppose we are editing a template for a list page of articles, where we need to display the creation time of each article. The creation time of the articles is usually accessed throughitem.CreatedTime(InarchiveLista loop) orarchive.CreatedTime(InarchiveDetailSuch variables can be accessed, they all store 10-digit Unix timestamps. We can use them in the template like thisstampToDateTags:

<span>发布日期:{{ stampToDate(item.CreatedTime, "01-02") }}</span>

In this code block,item.CreatedTimeRepresents the creation timestamp of the current looping article. When the template engine parses this line of code,stampToDatethe tag will receive this timestamp and follow the specifications we have indicated"01-02"Format it. Finally, on the web page, you will see something similar06-30/11-25This concise and clear date display perfectly meets the need to only display "month-day".

Further customization of date format

stampToDateThe power of labels goes beyond this, its flexibility can help you meet various date display needs.Once you master the reference time principle of the Go language, you can freely combine date formats that match the style of your website.

For example, if you need to display the full "year-month-day" format, you can write it like this:{{ stampToDate(item.CreatedTime, "2006-01-02") }}The output is as follows2023-06-30.

If you want to display a 'Year-Month-Day' format with Chinese, you can write it like this:{{ stampToDate(item.CreatedTime, "2006年01月02日") }}The output is as follows2023年06月30日.

If you only need to display time to the 'hour:minute' precision, you can do it like this:{{ stampToDate(item.CreatedTime, "15:04") }}The output is as follows12:30.

It is not difficult to see from these examples that no matter what date formatting needs you have, you just need to refer to the reference time of the Go language and write the desired format string with its corresponding parts.

Cautionary notes and **practice

While usingstampToDateWhen labeling, there are several small details worth your attention to ensure that the date display is always accurate.

  • The accuracy of the timestamp: stampToDateThe label expects to receive a standard 10-digit Unix timestamp (second level).If your timestamp is in milliseconds (13 digits), you may need to process it first, such as dividing by 1000, although Anqi CMS usually handles it internally, but knowing this helps in troubleshooting.
  • The accuracy of the format string:Be sure to refer to the Go language'sMon Jan 2 15:04:05 MST 2006This reference time to write the format string. Any characters that do not match this (unless they are separators or plain text) may cause the formatting result to be incorrect.
  • Make good use of the document field:In AnQi CMS,archive.CreatedTimeoritem.CreatedTimeIt is the most commonly used method to obtain the content creation timestamp, whilearchive.UpdatedTimeoritem.UpdatedTimeis used to obtain the last update time of the content. Choose the appropriate field according to your needs.
  • Maintain the date format of the website consistently:To enhance user experience and website professionalism, it is recommended to use a unified date display format throughout the website.For example, once it is decided that both the article list and detail pages use the "month-day" format, try to maintain consistency.

Summary

BystampToDateLabels, Anqi CMS makes date formatting intuitive and powerful.Just understand the reference time formatting rules of the Go language, and you can easily convert the original timestamp into various user-friendly date displays, including the concise "month-day" format that we focus on today.Master this little trick, and it will make your Anqi CMS website more refined and professional in detail.

Frequently Asked Questions (FAQ)

Q1: I inputtedCreatedTimeSometimes errors or unexpected results may occur, what are the reasons?A1: This usually has several reasons: first, make sureCreatedTimeIt is indeed a 10-digit Unix timestamp (in seconds). If it is in another format or length

Related articles

How to avoid page display exceptions caused by `stampToDate` format string error in AnQi CMS template?

As an experienced website operations expert, I am well aware that every detail of website content management is related to user experience and brand image.AnQiCMS (AnQiCMS) benefits from its efficient architecture based on the Go language and its flexible template system, providing strong support for content management.However, even the most excellent system may encounter some small challenges in the customization process.

2025-11-07

Can the `stampToDate` tag handle invalid or non-10-digit timestamps and what will it return?

As a senior website operations expert, I am well aware of AnQiCMS's efficiency and flexibility in content management.It provides us with rich and practical template tags, allowing us to build web pages with great freedom.Among them, the `stampToDate` tag is undoubtedly an important tool for handling time display, it can transform the boring Unix timestamp into the date and time format we are familiar with.However, any tool has its predefined boundaries of use, and it is particularly important to understand its behavior patterns when the input data does not meet expectations.

2025-11-07

`prevArchive` and `nextArchive` tags get the document time, how to use `stampToDate` to unify the format?

In the daily operation of Anqi CMS, we are well aware that the details of content presentation often determine the quality of user experience.A high-quality article is not only engaging in content, but also crucial in terms of layout and information presentation professionalism.Among them, the unified formatting of the article publication time is a detail that is small but can greatly enhance the professionalism of the website.

2025-11-07

How to use `stampToDate` to display the `ExpireTime` deadline of VIP members in the user center?

## Security CMS Practical: Display VIP membership expiration date elegantly in the user center, say goodbye to timestamp troubles!In modern content operation, the VIP membership system is an important link in enhancing user stickiness and achieving content monetization.The AnQi CMS, with its flexible user group management and VIP system, allows you to easily build paid content or membership services.However, how to display the `ExpireTime` (expiration time) of VIP members in a way that is intuitive and easy to understand for users, to avoid the confusion caused by the original timestamp, is the key to improving user experience.

2025-11-07

Can the `stampToDate` tag convert timestamps to full Chinese date descriptions, such as 'October 1, 2023'?

## Insight AnQiCMS: Deep Analysis of `stampToDate` Tag and Full Chinese Date Descriptions In website content operation, the accuracy and diversity of time display are crucial for improving user experience and meeting specific business needs.For senior content operators, skillfully handling the template tags of a content management system (CMS) and transforming technical abilities into actual operational effects is the core of daily work.

2025-11-07

How to implement localized date format display in `stampToDate` of a multilingual website template?

In today's globalized digital world, website operators all know the importance of content localization.Especially for multilingual websites, it's not just the translation of text content, but also elements like dates and times that seem trivial need to be localized according to the cultural habits of the target users.AnQiCMS is a content management system tailored for small and medium-sized enterprises and content operation teams, deeply understanding this field, and providing powerful date format localization capabilities through its flexible template engine.

2025-11-07

What is the specific meaning of the format string "`2006-01-02 15:04:05.999999999 -0700 MST`" in the `stampToDate` tag?

## Unveiling the AnQiCMS `stampToDate` tag: The mysteries of Go language string formatting for date-time

2025-11-07

How to use `stampToDate` to display the publication time of each comment in the Anqi CMS comment list?

Good, as an experienced website operations expert, I know that every detail can affect user experience.In Anqi CMS, present the publication time of the comment list in a clear and understandable way, which can not only improve the user experience but also make the website content look more timely and professional.Today, let's delve into how to cleverly use the `stampToDate` tag in the Anqi CMS comment list to make the publishing time of each comment clear at a glance.

2025-11-07