How to display the current year or other system time information in the template?

Calendar 👁️ 86

In website operation, keeping your content up-to-date in real-time, especially information like system time such as year or date, not only enhances the professionalism of the website but also provides users with more accurate reference.AnQiCMS as a flexible and efficient content management system provides various convenient ways for you to easily realize this requirement.

Next, let's learn together how to flexibly display the current year or other system time information in the AnQiCMS template.

Directly display the current system time——{% now %}Tag

In AnQiCMS templates, if you need to directly obtain and display the current year, date, or specific time of the website visit,{% now %}Tags are your good helper. The use of this tag is very intuitive, you just need to follow it with a string representing the time format.It should be noted that, AnQiCMS is developed based on Go language, so the time format string follows the special conventions of Go language rather than the common onesY-m-dformat.

For example, if you want to display the current year as copyright information at the bottom of the website:

{# 只显示当前年份 #}
© {% now "2006" %} 您的网站版权所有。

If you need to display the full date (year, month, day), for example in the header or a specific area:

{# 显示完整的年月日 #}
今天是:{% now "2006年01月02日" %}

If the content requires more accuracy, detailed date and time should be displayed:

{# 显示详细的日期和时间 #}
当前时间:{% now "2006-01-02 15:04:05" %}

This is very useful in the footer copyright statement of the website, once set, the year can be automatically kept up to date, saving the trouble of manual updates every year, keeping the website content always fresh.

Format the timestamp in the article or data -{{ stampToDate() }}function

In addition to displaying the current system time, we are more often faced with the need to format the time information stored in the database (usually in timestamp format) for display.For example, the publication date or the latest update time of an article.

AnQiCMS provides a very convenientstampToDateA function that can convert a 10-digit Unix timestamp to the desired date and time format. You can findarchiveList/archiveDetailthe document data obtained from the tags.CreatedTime(Creation Time) orUpdatedTime(Update time), they are all timestamps.

Here are some uses ofstampToDateExample of a function:

To display the publication date of the article, only keep the year, month, and day:

{# 显示文章的发布日期 #}
发布于:{{ stampToDate(archive.CreatedTime, "2006年01月02日") }}

If you need to display the update time to the minute:

{# 显示精确的更新时间 #}
上次更新:{{ stampToDate(archive.UpdatedTime, "2006-01-02 15:04") }}

If your design requires a more concise format, such as displaying only the month and date:

{# 只显示月份和日期 #}
{{ stampToDate(item.CreatedTime, "01-02") }}

This is an indispensable feature for scenarios that require displaying specific time points for blog posts, news updates, product release dates, etc., ensuring that users can clearly obtain time information while browsing the content.

Go language time formatting string tips

Understanding the time formatting rules of the Go language is the key to mastering the AnQiCMS time display. It is unlike some other systems that useY-m-d H:i:sSuch a placeholder, instead using a special reference time:2006年01月02日 15时04分05秒(Can also be understood as)1月2日周一 下午03:04:05 MST 2006)

You can treat each number or letter in this reference time as a placeholder for its corresponding time part. For example:

  • 2006Represents a four-digit year (e.g., 2023)
  • 01Represents two-digit months (e.g., 09)
  • Represents the Chinese character representation of the month
  • 02Represents two-digit dates (e.g., 15)
  • Represents the Chinese character representation of the date
  • 15represents the hour in 24-hour format (e.g., 14)
  • 04represents the two-digit minute (e.g., 30)
  • 05represents the two-digit second (e.g., 59)
  • MonAbbreviation for the day of the week (e.g., Wed)
  • MondayFull name for the day of the week (e.g., Wednesday)
  • PMRepresenting AM/PM (e.g., AM)
  • MSTor-0700Representing time zone

By flexibly combining these elements, you can build any date and time format you want.For example, to display "September 15, 2023, Wednesday, 10:30 AM", you can try such a combination of formats.

In general, AnQiCMS is powerful and flexible in handling time information in templates.Whether it is to display the real-time system time of a website or to present the release update time of an article in an aesthetic way, it can be easily achieved through simple tags and functions.Understanding the time formatting rules in Go language will help you better master these features, making your website content management more convenient.


Frequently Asked Questions (FAQ)

Q1: Why my{{ stampToDate(...) }}The function displays the time incorrectly?

A: First, please check what you pass tostampToDateIs the timestamp of the function a 10-digit integer, which is usually a Unix second timestamp.If your timestamp is a 13-digit millisecond timestamp, you need to divide it by 1000 first to convert it to a second-level timestamp. For example:{{ stampToDate(archive.CreatedTime / 1000, "2006-01-02") }}. Secondly, confirm that your format string strictly follows the Go language's reference time `2006

Related articles

How does the automatic compression of images and the handling of large images in content settings affect page display performance?

In website operation, images are indispensable elements that enrich content and attract users.However, if image processing is not handled properly, the large file size often becomes the culprit that slows down page loading speed, thereby affecting user experience and search engine optimization (SEO) performance.AnQiCMS provides a series of powerful image processing features in its content settings, aimed at helping us easily optimize images and significantly improve the display performance of the website.When a visitor opens a page, the browser needs to download all the resources on the page, including text, styles, scripts, and images.If the image file is too large

2025-11-08

How do static rules affect the display form and SEO-friendliness of website URLs?

## Static rule of AnQi CMS: How to create a URL structure that users and search engines both love In the operation of a website, the URL is not only the path for users to access the page, but also an important clue for search engines to understand and evaluate the content of the website.A clear, concise, and meaningful URL that greatly enhances user experience and website SEO performance.AnQi CMS knows this, and therefore provides a flexible and diverse static rule management function to help us easily create an ideal URL structure.What is pseudo-static and why is it so important

2025-11-08

How does Anqi CMS manage and display uploaded images and video resources?

When using Anqi CMS to manage website content, images and video resources are undoubtedly the key to enriching the page and improving the user experience.AnQi CMS provides a set of intuitive and powerful functions to help us efficiently upload, manage, and display these multimedia contents. ### Easy upload and centralized management of resources When creating articles, products, or single-page content, images and videos can be directly inserted into the content editing area.This process is very smooth, just like using a document editor in everyday life.In addition to this immediate insertion method, Anqi CMS also has a dedicated "image resource management" area

2025-11-08

How to define template variables and reuse them in content display?

In AnQi CMS, managing and displaying website content, flexibly using template variables is undoubtedly the key to improving efficiency and maintaining consistency.Whether it is necessary to unify the information of the entire site or to customize unique attributes for specific content, understanding how to define and reuse template variables can make content operation more skillful. ### From the background source to define variables In AnQi CMS, many of the information we see on the website every day is actually managed through backend predefined variables.This means you don't have to touch a single line of code to easily define and modify these contents. First

2025-11-08

How to deploy multiple AnQiCMS sites on the same server and ensure their independent display?

Deploying multiple websites on the same server while ensuring that they run and display independently is a common need for many content operators.For AnQiCMS users, this is not only feasible but also very efficient.The Anqi CMS leverages its powerful multi-site management features, allowing you to easily manage multiple brand sites, sub-sites, or content branches with just one core program.Next, we will discuss in detail how to deploy and manage multiple security CMS sites cleverly on the same server, so that they operate independently without interfering with each other.### Core Concept

2025-11-08

How to add structured data (JSON-LD) in the HTML header to improve search result display?

In today's highly competitive online environment, it is crucial to make your website content stand out in search engine results pages.In addition to high-quality content and an excellent keyword strategy, structured data (especially in JSON-LD format) plays an increasingly important role.It can help search engines understand the information on your page more accurately, so that your content may be displayed in richer, more attractive forms in search results (such as rich media summaries, i.e., Rich Snippets).What is JSON-LD and why should it be used

2025-11-08

How to enable and display captcha in the comment or message form?

In website operation, the message and comment functions are important channels for interacting with users and collecting feedback.However, this is often accompanied by the困扰 of spam and malicious flooding.To effectively filter out this unnecessary content, enabling the captcha mechanism has become a simple and efficient solution.AnQiCMS (AnQiCMS) provides us with a flexible way to easily integrate captcha functionality into comment or message forms. Next, we will learn in detail how to enable and display the captcha in Anqi CMS.### Step 1: Turn on captcha feature in the management background First

2025-11-08

How can language switch links be displayed in multilingual sites?

Build a website for global users, multilingual support is an indispensable part.AnQiCMS was designed with this in mind, providing a powerful and flexible solution for the publication and management of multilingual content.By making some simple configuration and template adjustments, we can easily implement language switching functionality on the website, allowing users of different languages to smoothly browse the website content.### AnQiCMS' multilingual capabilities AnQiCMS is inherently equipped with excellent multilingual content management capabilities

2025-11-08