How to get and display the day of the week corresponding to the timestamp in the AnQi CMS template using `stampToDate`?

Calendar 👁️ 66

Unlock time magic: Easily display 'which day of the week' in Anqi CMS template

As an experienced website operations expert, I know the importance of content timeliness and presentation for user experience and information communication.In such a flexible and efficient content management system as AnQiCMS, we can not only easily manage a variety of content, but also finely control every detail of content display through its powerful template engine.stampToDateThe function converts timestamps into readable dates and further extracts and displays the corresponding 'which day of the week'.

AnQiCMS template: The combination of efficiency and flexibility

AnQiCMS's template system adopts a syntax similar to the Django template engine, which means you can build the layout and content of the page with concise and intuitive tags and variables. Such as{{变量}}Used for output data, and{% 标签 %}It is used to implement logical control or call specific functions.This design philosophy allows non-technical operation personnel to master the essentials of template modification through simple learning, thus quickly responding to the changes in content display requirements.

Our template files are usually stored in/templatethe directory and use.htmlAs a suffix. In these templates, you will frequently deal with various built-in tags and functions provided by AnQiCMS,stampToDatewhich is one of the tools for processing time data.

stampToDateThe Art of Timestamp Conversion Unveiled

In website content, especially in news articles, event schedules, or update logs, we often encounter time data stored in the form of timestamps (usually 10-digit Unix timestamps, representing the number of seconds from 1970-01-01 00:00:00 UTC to the present).These numbers displayed directly are meaningless to the user.stampToDateThe emergence of functions is to solve this pain point

Its basic usage is very intuitive:{{stampToDate(时间戳, "格式")}}The key is the second parameter - 'format'. Unlike what we commonly useyyyy-MM-ddThe format is slightly different, AnQiCMS is developed based on Go language, so its time formatting follows the unique Go language formatReference time formatThis reference time is a fixed value:2006年1月2日 15点04分05秒You need to match the output format you expect with the corresponding part of this reference time.

For example, if you want to display2023-10-26 10:30:00The format string should be"2006-01-02 15:04:05".

Core technique: How to get and display the day of the week

Now, let's solve the core problem of the article: how tostampToDateGet and display the day of the week corresponding to the timestamp.

In the date formatting rules of the Go language, to represent the day of the week, we can use the following two reference values:

  • MondayThis will output the full name of the week, for example, "Monday", "Tuesday".
  • MonThis will output abbreviated names of weekdays, such as 'Mon', 'Tue.'

Therefore, to get a timestamp (such as the publication time of an articleitem.CreatedTimeWe can extract the day of the week and display it on the template like this:

Suppose you are iterating through a list of articles, and each article's data object isitemwhich contains aCreatedTimeThe field stores a 10-digit timestamp.

If you want to display the full name of the week, such as 'Monday', 'Tuesday', you can write it like this:

{# 假设item.CreatedTime是一个10位时间戳 #}
<p>发布日期:{{ stampToDate(item.CreatedTime, "2006年01月02日 Monday") }}</p>

After running, the page may display content similar to "Publish date: October 26, 2023, Thursday".

If you prefer to display abbreviated names of weekdays such as "Monday", "Tuesday", you can useMonas part of the format:

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

The page will display the effect of "Published date: 2023-10-26 Thu".

You can also just display the day of the week without the date part, just keep the format string.MondayorMonand it is done:

<p>今天是:{{ stampToDate(item.CreatedTime, "Monday") }}</p>

This will output: "Today is: Thursday."

This technique can be applied to any AnQiCMS data field that contains a timestamp, such as the document'sCreatedTime(Creation time) orUpdatedTime(Update time), even any timestamp field defined in the custom content model.It greatly enhances the readability and user experience, making your website information more friendly and easy to understand.

Practical application scenarios and precautions

Integrating weekdays into your content display can bring many benefits:

  • Enhance user experienceUsers do not need to calculate it themselves, they can obtain date information at a glance, which is crucial for content such as events, news, or blog articles.
  • Enhance the value of informationFor example, clearly marking the day of the week when publishing weekly reports or regular updates helps users quickly locate information.
  • Optimize content presentationMake date information more complete and humanized, in line with daily reading habits.

While usingstampToDateWhen defining a function, there are several points to pay special attention to:

  1. Formatting rules for the Go language: Always remember the unique reference time format of Go language2006-01-02 15:04:05. All format strings should be based on this, not the commonY-m-detc.
  2. Timestamp digit:stampToDateThe function expects a 10-digit Unix timestamp (seconds).If your time data is a 13-digit millisecond timestamp, you may need to divide it by 1000 first, convert it to 10 digits, and then format it.
  3. Variable type confirmation: Make sure you pass tostampToDateThe first parameter is indeed a valid numeric type timestamp. AnQiCMS built-inCreatedTimeandUpdatedTimefield is usually stored as a 10-digit timestamp and can be used directly.

MasteredstampToDateThis function's trick will allow you to control the display of time information on the AnQiCMS website more flexibly and accurately, enhancing your content operation strategy to a higher level.

Frequently Asked Questions (FAQ)

  1. Why do I usestampToDateWhen displaying the day of the week, the output is English instead of Chinese?AnQiCMS'stampToDateThe function is based on the built-in time formatting feature of the Go language, which defaults to outputting the English names of weekdays (such as "Monday" or "Mon"). To display the Chinese weekday names (such as "Monday"),stampToDateThe function does not provide this feature directly. You may need to combine it with front-end JavaScript for localization conversion, or through the AnQiCMS template,{% if %}Or customize the mapping logic to output the corresponding Chinese based on the English day of the week.

  2. I have a 13-digit timestamp, how do I use it directly?stampToDateHow do I fix the incorrect display after? stampToDateThe function is designed to handle a 10-digit Unix timestamp (seconds).If you have a 13-digit millisecond timestamp, you need to divide it by 1000 before passing it to the function.item.MillisecondTimeYou may need to handle it like this:{{ stampToDate(item.MillisecondTime / 1000, "Monday") }}.

  3. In addition to the days of the week, I can also usestampToDateWhat other date and time information can the function obtain?Of course! Just refer to the reference time in the Go language2006-01-02 15:04:05You can combine almost any date and time format you need. For example:

    • "2006": Year (four digits)
    • "01": Month (with leading zero)
    • "_1"Month (without leading zero, with space for single digits)
    • "02"Date (with leading zero)
    • "_2"Date (without leading zero, with space for single digits)
    • "15"Hour (24-hour format, with leading zero)
    • "03": Hour (12-hour format, with leading zero)
    • "04": Minute (with leading zero)
    • "05": Second (with leading zero)
    • "PM"or"pm": AM/PM indicator
    • "MST"or"Z07:00": Time zone information By flexibly applying these rules, you can achieve various complex date and time display requirements.

Related articles

If the `archive.CreatedTime` field is empty, how will `stampToDate` handle and display?

As an experienced website operations expert, I know that the timeliness of content is crucial for user experience and SEO optimization.AnQiCMS (AnQiCMS) with its powerful content management and flexible template system, allows us to efficiently handle these requirements.In content display, handling the publication time is a common and critical link, we usually use the `stampToDate` template tag to format the timestamp data from the backend into a user-friendly date and time format.

2025-11-07

How to further process the formatted date string from `stampToDate` using other filters (such as truncation)?

In the Anqi CMS template world, we often need to convert timestamps (`timestamp`) into readable date and time strings.The `stampToDate` label function is undoubtedly a good helper for us to achieve this goal.It can beautifully present a 10-digit timestamp according to the Go language date format, like "2023-06-07 15:30:00".However, the actual needs of website operation always change.

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

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

Are there any special considerations when using the `stampToDate` tag in the Anqi CMS multi-site environment?

As an experienced website operation expert, I have accumulated rich experience in the practical application of AnQiCMS, especially feeling deeply about the flexible use of template tags.Today, let's delve deeply into the commonly used `stampToDate` tag, and when it is called in the multi-site environment of AnQiCMS, are there any points that need special attention?AnQiCMS is an efficient and customizable enterprise-level content management system, and its multi-site management function is one of its core advantages.It allows users to manage multiple independent sites on a unified backend

2025-11-07

Can `stampToDate` format timestamps into ISO 8601 standard format (such as "YYYY-MM-DDTHH:MM:SSZ")?

As an experienced website operation expert who deeply understands the operation of AnQiCMS, I fully understand the importance of time formatting, especially standardized time formats, in content management.Today, let's delve into the `stampToDate` tag of Anqi CMS to see if it can format timestamps into ISO 8601 standard format, such as the `"YYYY-MM-DDTHH:MM:SSZ"` we often see.### AnQi CMS's `stampToDate`: Easily format timestamps to ISO

2025-11-07

How can the scheduled publishing function of AnQi CMS accurately display the publish time on the front end through `stampToDate`?

As an experienced website operation expert, I am well aware of the art of content release timing and its profound impact on user experience, search engine optimization, and even operation efficiency.AnQiCMS (AnQi CMS) is exactly born to meet these needs, and its 'Time Factor-Scheduled Publication Function' is a powerful tool in the hands of content operators.But having a strong publishing capability is not enough, how to present these carefully set publishing times elegantly and accurately to the readers is equally important.This is the place where the `stampToDate` template tag really shines.### Schedule Post Function

2025-11-07

Can the `stampToDate` label handle the millisecond precision of Unix timestamps?

In a content management system, the accurate display of time is crucial, especially when dealing with user behavior, data logs, or the release of specific events.AnQiCMS as a powerful content management system based on the Go programming language provides rich template tags to meet various content display needs, among which the `stampToDate` tag is a powerful tool for formatting timestamps.However, whether this tag can handle the millisecond level precision of Unix timestamps is a concern for many operators and developers.We can see from the official documentation of AnQiCMS

2025-11-07