Good, I am very happy to delve into the AnQiCMS for you.stampToDateTags, help you easily handle the time display on the website.
Flexible time handling: Make use of AnQiCMS's.stampToDateLabel customization date and time format
In website content management, the way dates and times are displayed often directly affects user experience and the clarity of information communication.A concise, readable date format can help visitors quickly understand the timeliness of the content.AnQiCMS as an efficient content management system, knows this well and provides powerful and easy-to-usestampToDateLabel, allowing you to easily format the Unix Timestamp stored in the database into various custom date and time formats.
Understanding Timestamps: The Source of Your Content's Time
Within AnQiCMS, there are many time-related pieces of information, such as the publication time of articles (CreatedTime)、Update Time(UpdatedTime), comment time, even the latest login time of the user, are all stored in the form of timestamps.Timestamp is typically a 10-digit number representing the number of seconds elapsed since 00:00:00 on January 1, 1970, Greenwich Mean Time (UTC). For example,1678886400Such numbers are very efficient for computers, but it is difficult for ordinary visitors to understand their exact meaning.
This brings up our need for time formatting, converting these original numbers into a format that people are accustomed to reading, such as "2023-03-15 10:00:00" or "3 days ago."}
stampToDateThe core usage of tags
stampToDateThe usage of tags is very intuitive:
{{ stampToDate(时间戳, "格式") }}
The key lies in the second parameter - the format string. Many other systems adoptYYYY-MM-DDThis placeholder is different, AnQiCMS internally uses the Go language time formatting standard, which has a fixed 'reference time'.You need to replace the date and time elements you expect to display with the corresponding part of this reference time.This reference time is:
2006-01-02 15:04:05.999999999 -0700 MST(usually abbreviated as2006-01-02 15:04:05)
This is like a 'magic number', which is not an actual year but a placeholder used by the Go language to identify the position of time elements. Just remember that when you want to display the year in the result, just write2006; If you want to display the month, you write01; To display the date, write02and so on.
Let's understand it through some examples of common formats:
- Only display the year:
{{ stampToDate(publishStamp, "2006") }}→2023 - Year-Month-Day:
{{ stampToDate(publishStamp, "2006-01-02") }}→2023-03-15 - Year/Month/Day:
{{ stampToDate(publishStamp, "2006/01/02") }}→2023/03/15 - Month/Day/Year (commonly used for internationalization):
{{ stampToDate(publishStamp, "01/02/2006") }}→03/15/2023 - Hour:Minute:Second (24-hour format):
{{ stampToDate(publishStamp, "15:04:05") }}→10:00:00 - Year-Month-Day Hour:Minute:
{{ stampToDate(publishStamp, "2006-01-02 15:04") }}→2023-03-15 10:00 - Complete format with Chinese:
{{ stampToDate(publishStamp, "2006年01月02日 15时04分05秒") }}→2023年03月15日 10时00分00秒 - When is the day:
{{ stampToDate(publishStamp, "Mon") }}→Wed(Wednesday)
Please note that other characters in the format string, such as dashes, slashes, colons, spaces, and Chinese characters, will be output as is, serving as separators or descriptions.
tostampToDateApply to your website: actual scenario examples
stampToDateTags are everywhere in AnQiCMS template development, especially in scenarios where content publishing or update time needs to be displayed.
1. Display the publication and update time on the document detail page
When you are browsing an AnQiCMS article, you will usually see its publication date. Assume you arearticle/detail.htmlIn the template, you can usearchiveDetailLabel to get document details and format the timestamps within.
<article>
<h1>{% archiveDetail with name="Title" %}</h1>
<div class="meta-info">
<span>发布于:{{ stampToDate(archive.CreatedTime, "2006年01月02日 15:04") }}</span>
<span>更新于:{{ stampToDate(archive.UpdatedTime, "2006-01-02") }}</span>
<span>浏览量:{% archiveDetail with name="Views" %}</span>
</div>
<div class="article-content">
{% archiveDetail articleContent with name="Content" %}{{ articleContent|safe }}
</div>
</article>
This code will takearchive.CreatedTimeFormat to an accurate Chinese date and time to the minute, butarchive.UpdatedTimeonly show to the day.
2. The article publication date is displayed on the document list page
On the article list page, you may want to display the publication date next to each article so that visitors can quickly understand the order and timeliness of the content.
<ul class="article-list">
{% archiveList archives with type="page" limit="10" %}
{% for item in archives %}
<li>
<a href="{{ item.Link }}">
<h3>{{ item.Title }}</h3>
<p>{{ item.Description|truncatechars:100 }}</p>
<div class="list-meta">
<span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
<span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
<span>阅读量:{{ item.Views }}</span>
</div>
</a>
</li>
{% empty %}
<li>暂无文章内容。</li>
{% endfor %}
{% endarchiveList %}
</ul>
here,item.CreatedTimeIs formatted in each loop.YYYY-MM-DDForm.
3. Comment time displayed in comments
If your website has a comment function, then the posting time of each comment is also a focus for users.
`twig