Can the `stampToDate` tag customize the display of the English abbreviation of the month, such as "Jan", "Feb"?

Calendar 👁️ 60

Of Security CMSstampToDateLabel: Customize time format flexibly, easily display month abbreviations

As an experienced website operations expert, I know that both the accuracy and beauty of time are equally important in content display.AnQiCMS (AnQiCMS) provides strong support for content operations with its efficient and customizable features.In daily operations, we often need to convert timestamps in databases to user-friendly date formats.AnQi CMS provides a very practical template tag -stampToDate.

Recently, many friends have asked about Anqi CMSstampToDateCan the label be customized to display the English abbreviation of the month, such as "Jan", "Feb", and such?The answer is affirmative, not only can it, but it is also very flexible, thanks to the time formatting mechanism of the underlying Go language in AnQiCMS.

Deep understandingstampToDateLabel and Go language time formatting

In AnQiCMS template design,stampToDateLabels are the core tools for processing timestamp conversion. Their basic usage method is{{stampToDate(时间戳, "格式")}}. The 'timestamp' is typically a 10-digit Unix timestamp, and the 'format' is the key to determining the output date and time style.Understand this "format" parameter, it is the first step to customize the display of month abbreviations.

Go language has a unique and very efficient 'reference time' concept when handling time formatting. This reference time is not a randomly chosen date, but a fixed one:Mon Jan 2 15:04:05 MST 2006. We just need to replace the corresponding part of this reference time with the display format we want, and the Go language will intelligently apply it to the actual timestamp. For example:

  • 2006Represent a four-digit year (e.g., 2023)
  • 01Represent a two-digit month (e.g., 01, 02...12)
  • JanRepresent the English abbreviation of the month (such as Jan, Feb…Dec)
  • JanuaryRepresent the full English name of the month
  • 02Represent the two-digit date
  • 15Represent the hour in 24-hour time format
  • 03Represents the hour in 12-hour format
  • 04Represents the number of minutes
  • 05Represents the number of seconds
  • MonRepresents the English abbreviation for the day of the week
  • MondayRepresents the full English name for the day of the week

mastered this reference time mapping, we can customize the time display format at will.

easily achieve the display of month English abbreviations

Now let's return to our core question: how to display the English abbreviation of the month? According to the formatting rules of the Go language, we only need to use the format string "JanThis identifier can be used tostampToDateLabels display the month as an English abbreviation.

For example, if we want to display the publication time of an article (usually stored as a timestamp, such asitem.CreatedTimeDisplayed in the format "Jan 02, 2023", the template code can be written like this:

<div>发布日期:{{stampToDate(item.CreatedTime, "Jan 02, 2006")}}</div>

If you want to add the year in front of the date, for example, "2023 Jan 02", you can adjust the format string to:

<div>发布日期:{{stampToDate(item.CreatedTime, "2006 Jan 02")}}</div>

Even more complex combinations, for example, displaying “02-Jan-2023”, can also be easily achieved:

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

In this way, we can see that AnQiCMS'sstampToDateTags provide high flexibility, allowing content operators to freely adjust the display format of date and time according to the style of the website, target audience, or internationalization needs, without the need for complex secondary development.

More practical time formatting techniques

In addition to the English abbreviations for months, mastering the reference time format of the Go language can unlock more practical date and time display methods, greatly enriching our content presentation.

  • Full English month name: If you need to display the full month name, such as "January", just use the format stringJanuaryand it is done:
    
    <div>完整月份:{{stampToDate(item.CreatedTime, "January 02, 2006")}}</div>
    
  • Display of the day of the weekTo display the abbreviation of the day of the week, such as 'Mon', useMonTo display the full name, such as 'Monday', useMonday:
    
    <div>发布时间:{{stampToDate(item.CreatedTime, "Mon, Jan 02, 2006")}}</div>
    <div>发布时间:{{stampToDate(item.CreatedTime, "Monday, January 02, 2006")}}</div>
    
  • Time to the second: Combined with the format of hours, minutes, and seconds, it can display more precise time:
    
    <div>精确时间:{{stampToDate(item.CreatedTime, "2006-01-02 15:04:05")}}</div>
    
    Here15Represents 24-hour time format, if you need 12-hour format with AM/PM, you can use03:04:05 PM.

In the AnQiCMS template files, such as the article detail page ({模型table}/detail.html) or the list page ({模型table}/list.html), we can obtain the timestamp through variables such asitem.CreatedTimeorarchive.CreatedTimeand then combine withstampToDateTags and the above formatting techniques, present time information in the most fitting way for content and user habits.This meticulous customization capability is exactly the embodiment of the 'efficient and customizable' value pursued by AnQiCMS as an enterprise-level content management system.It allows the content of the website to appear in a more professional and international manner after publication, enhancing the overall user experience and brand image.


Frequently Asked Questions (FAQ)

1.stampToDateDoes the label support displaying the full month name, such as "January" or "February"?Of course it does. Similar to displaying the month abbreviation, you just need tostampToDateThe format string contains, willJanReplaceJanuaryit is. For example,{{stampToDate(item.CreatedTime, "January 02, 2006")}}It will display as “January 02, 2023”. Go language time formatting is achieved by matching the corresponding parts of the reference time.

2.stampToDateCan the label directly display Chinese months, such as 'January' or 'February'? stampToDateThe tag directly works through the built-in date formatting rules of the Go language, and its reference time (Mon Jan 2…) uses English.Therefore, it cannot directly output Chinese months like 'January' and 'February' through a format string.If you need to display Chinese months, you may need to combine the AnQiCMS multi-language feature (if a corresponding language package is set), or process it twice in the template through conditional judgment and mapping table, converting English month abbreviations or numeric months manually into Chinese.

3. Why?stampToDateThe format of the label string looks strange, for example, '2006-01-02 15:04:05' instead of 'YYYY-MM-DD HH:mm:ss'?This is indeed a feature of Go language time formatting. Go language does not adopt commonYYYY-MM-DDsuch symbol placeholders, but uses a fixed "reference time"-2006年1月2日(周一)下午3点04分05秒,位于MST时区. Any numeric or alphabetical combination you write in the format string, Go will try to match it to the corresponding part of this reference time to generate the date and time format you want. For example,2006represents the year,01represents the month,02represents the date,15Represents hours in a 24-hour format and so on. Although it may seem a bit unusual at first glance, once you grasp its rhythm, you will find it very flexible and powerful.

Related articles

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

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 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

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 extract only the year from the timestamp using `stampToDate` in the AnQi CMS template?

As an experienced website operations expert, I know that it is crucial to efficiently and flexibly display information in daily content management.AnQiCMS (AnQiCMS) leverages the efficient features of the Go language and the template syntax of Django style, providing us with powerful content display capabilities.Today, we will focus on a very practical little trick in the Anq CMS template: how to extract only the year from the timestamp using the `stampToDate` tag.

2025-11-07

Does the `stampToDate` tag support formatting timestamps into the international date format "MM/DD/YYYY"?

In the daily operation of AnQiCMS, the formatting of the Unix timestamp is a common requirement, especially when our website content needs to be targeted at international users, the flexibility of the date display format is particularly important.Today, let's delve deep into the `stampToDate` tag in AnQiCMS to see if it can meet our needs to format timestamps into the international date format of "MM/DD/YYYY".

2025-11-07

In the `archiveList` loop, how does `stampToDate` ensure that each `item.CreatedTime` is formatted correctly?

## Mastering Time: The Art of Date Formatting in AnQiCMS' `archiveList` Loop In the world of content management, information such as the publication time and update time of website content is not only a key element for providing context to readers, but also an important indicator of a website's professionalism and user experience. For AnQiCMS, an enterprise-level content management system based on Go language and focusing on efficiency and flexibility, how to elegantly present the original timestamps stored in the database to users is a significant issue.

2025-11-07

What is the core difference between the `stampToDate` and the `date` filter mentioned in `tag-filters.md`?

As an experienced website operations expert, I know that the accurate display of time information is crucial for user experience and SEO optimization.In the powerful template system of AnQiCMS, we often encounter scenarios where we need to format time data for output.At this moment, `stampToDate` and `date` are two tools that seem to have similar functions and appear in our minds.However, there is a core distinction between them, understanding this distinction is crucial for efficient and error-free template development.

2025-11-07