What is the main difference between the `now` tag and the `stampToDate` tag in the time display in `tag-system.md`?

Calendar 👁️ 67

As an experienced website operations expert, I am well aware that how to flexibly and accurately display time information in a content management system is crucial for the vitality of website content and user experience.AnQiCMS (AnQiCMS) has fully considered this point in the design of template tags and provided multiple methods for handling time.nowTags andstampToDateLabel, analyze the main differences in the display of time.

nowLabel: Capture the snapshot of the moment.

Imagine that you need the copyright year at the bottom of the website to always be up-to-date, or you want to display a real-time "current time" prompt on the page. At this point,nowThe tag is your ideal choice. Its design purpose is very pure: to obtainThe current system time of the serverand output it in the format you specify.

nowThe usage of the tag is concise and clear, for example{% now "2006" %}It can be directly displayed on the page to show the current year. If you want to display the full date and time, you can write{% now "2006-01-02 15:04:05" %}.The strength of this label lies in its 'immediacy' - it does not rely on any external time data input, but directly retrieves the current time point from the server.nowThe label can always accurately display the latest time at that moment.It is very convenient for displaying the copyright year of the website, the real-time dynamic update of the date identifier, or any time information that needs to reflect the "moment".

stampToDateTag: A painting of historical moments

withnowThe "immediacy" of tags is different,stampToDateThe label is more concerned with the "reproduction of history.In website content, we often need to display the publication time of articles, product update dates, or event deadlines, etc., these time points are already determined at the time of content creation or the occurrence of a specific event.They are stored as 'historical timestamps' in the database, not the current real-time time.

stampToDateThe core responsibility of tags is to represent an originaltimestamp (usually 10 digits)Presented elegantly according to the format you set. For example, in AnQi CMS, the publication time of a document may be stored asarchive.CreatedTimeSuch a timestamp field. You would use to display it in a readable date format{{stampToDate(archive.CreatedTime, "2006-01-02")}}. Here,archive.CreatedTimeThat is the timestamp passed in, and"2006-01-02"It is the format you wish to display. Whether it is the publish and update date on the article detail page, or the timestamp of user comments,stampToDateCan transform these static numbers into date strings with clear meanings, allowing readers to clearly understand the time when the event occurred.

The core difference: The source and processing of time information

Then, where is the main difference between these two tags that seem to be related to time formatting? In simple terms, the difference lies in how they obtain time information."Source".

nowThe label is a 'time provider', it directly asks the server 'What time is it now?'}]Please then format and output the answer.It does not care about any other time data, only focusing on the current system time.This is like, you glance at a calendar or clock and know the date and time right now.

AndstampToDateA label is a 'time processor'. It does not generate time information itself, but requires youto actively provide an existing timestamp.Its task is to 'translate' this timestamp into a human-readable date and time format.This is like picking up an old photograph that bears the date and time of a moment, and then deciding what kind of handwriting to copy it down in.The date on this photo will not change because of the moment you pick it up, it is a fixed historical record.

Therefore, when you need to display the "current" or "real-time" time, nowLabels are your preferred choice. When you need to format specific timestamps from databases or other places,stampToDateTags are the correct tools. Both take advantage of the flexible time formatting strings in Golang, which keeps them highly consistent and convenient in custom output.

How to choose the appropriate tag?

Understanding this difference at the source makes it clear and easy to choose.

  • UsenowTags:When you want to display dynamic real-time information on the website, such as the real-time copyright year in the footer, the latest generation time of the website, or any time point that needs to reflect the "current" moment when the page is loaded.
  • UsestampToDateTags:When you need to format the display of fixed timestamp data stored in content such as articles, products, user comments, etc., such as article publishing/update time, user registration time, event start/end dates, and so on.

These two tags are similar in purpose, but there are essential differences in the source and processing logic of time information. Mastering their correct usage will greatly enhance your efficiency and flexibility in content operations on AnQi CMS.


Frequently Asked Questions (FAQ)

  1. Question:stampToDateIs the first parameter of the label supposed to be a 10-digit timestamp? Do I use the date string directly?Answer: Yes,stampToDateThe first parameter of the labelMust be a 10-digit timestamp(Unix timestamp), it represents the number of seconds elapsed since 00:00:00 UTC on January 1, 1970. If you have a date string (such as "2023-01-01 10:30:00"), you cannot use it directly tostampToDateFormat.In this case, you may need to handle the conversion of date strings to timestamps on the backend, or check if AnQi CMS has other tags or filters that support date string formatting.

  2. Question:nowCan the tag be used to display the publication time of the article? This way, every time the article is visited, the time is the most up-to-date.Answer:nowThe tag is not suitable for displaying the publication time of the article becausenowThe label shows the time of website visitCurrent system time, while the publication time of the article is a fixed historical record, which will not change with user access. If usingnowDisplaying the publish time would make all articles look like they were "just published", which is obviously not in line with the actual situation. You should usestampToDateCombine the article data's publish timestamp field (for example{{stampToDate(archive.CreatedTime, "2006-01-02")}}) to correctly display the article's publish time.

  3. Ask: If I only want to get the number of the current month (for example, '1' represents January), how should I usenowOrstampToDate? What format string should I write?Answer: You should usenowThe tag, because it retrieves the current time. To display the number of the current month, you can use the Golang formatting string"01"So, the tag will be{% now "01" %}. If you need to display the full two-digit month (e.g., "01"), use"01"; If you only need to display a single digit (e.g., "1"), use"_1".

Related articles

In AnQiCMS, can the `stampToDate` tag handle date display habits of different regions (such as China and the United States)?

Unlock AnQiCMS `stampToDate`: Easily Master Global Date Display Habits In the wave of global content operations, the subtle differences in date and time formats often become key factors affecting user experience.A website that can intelligently adjust the date display according to the visitor's regional habits will undoubtedly greatly enhance its professionalism and user-friendliness.

2025-11-07

How to use the `stampToDate` formatted date in the HTML `datetime` attribute to improve SEO?

## The AnQi CMS Practical Guide: How to Fly Your Website's SEO Wings with `stampToDate` and HTML `datetime`?As an experienced website operations expert, I know that in the increasingly fierce internet competition, every detail may become the key to a website standing out.For SEO, content quality is indeed the core, but optimization at the technical level should not be ignored either.

2025-11-07

How to flexibly choose to display the date or time part in `stampToDate` instead of a fixed format?

## Fine control of time display: The secret manual of flexible application of `stampToDate` in AnQi CMS In website operation, the display of time information seems ordinary, but it contains a lot of knowledge to improve user experience and optimize content presentation.AnQi CMS knows this, and has provided a powerful and flexible timestamp formatting tool for webmasters —— `stampToDate`.Many new operators may be puzzled, as this function seems to always output a fixed date and time format, but in fact, by skillfully using its 'format' parameter, you can easily achieve displaying only the date

2025-11-07

Does the `stampToDate` tag have a default output format when no format string is provided?

As an experienced website operations expert, I fully understand the importance of handling time data in content management systems, especially ensuring that they are presented in the way we expect.AnQiCMS (AnQiCMS) has fully considered flexibility and efficiency in the design of template tags, and the `stampToDate` tag is a typical representative.Today, let's delve into a common question about this tag: When no format string is provided, will the `stampToDate` tag have a default output format?###

2025-11-07

How to perform security filtering on the date string generated by the `stampToDate` tag to prevent XSS attacks?

As an experienced website operation expert, I am happy to give you a detailed explanation of how to ensure the security of the date string generated by the `stampToDate` tag in AnQiCMS, effectively preventing XSS attacks. --- ### Ensure Security: How to effectively prevent XSS attacks in the date string generated by the `stampToDate` tag in AnQiCMS In the template development of AnQiCMS, the `stampToDate` tag is a powerful helper for us to process timestamps and format them into readable date strings.

2025-11-07

How to display the current website's name and Logo in Anqi CMS template?

As an experienced website operations expert, I am well aware of the importance of a website's name and logo in brand image and user recognition.In a powerful and flexible content management system like AnQiCMS, presenting these core brand elements in the website template not only enhances professionalism but also helps with search engine optimization (SEO).Today, I will give a detailed explanation of how to easily display the current website name and logo in AnQiCMS templates, making your brand shine in the eyes of users.--- ### AnQi CMS Template

2025-11-07

How to obtain and display the website's filing number and custom copyright information?

As an experienced website operations expert, I fully understand the importance of website compliance and brand information display for user trust and corporate image.AnQiCMS (AnQiCMS) provides powerful and flexible features in these aspects, allowing you to easily manage and display the filing number and custom copyright information of your website.Next, I will explain in detail how to implement these operations in AnQiCMS. --- ## How to obtain and display the record number and custom copyright information of a website?

2025-11-07

How to obtain the basic configuration information of a specified site when operating multi-site?

AnQiCMS (AnQiCMS) provides great convenience for operators with its excellent multi-site management capabilities.Whether it is multiple brand sites under your company, regional sub-sites, or the need to build independent content portals for different business lines, AnQiCMS can efficiently manage them on a unified backend.However, in actual operation, you may encounter such a scenario: in a site template, it is necessary to obtain the basic configuration information of another site, such as its website name, logo, URL, or contact information.

2025-11-07