In the daily operation of AnQi CMS, we often need to deal with fields related to time, such as the VIP expiration time of users (ExpireTime)。Correctly displaying these time information and making flexible conditional judgments based on their status is crucial for improving user experience and achieving personalized content display. This article will focus onExpireTimeField, detailed discussion on how to utilizestampToDateLabel for date formatting, combined with conditional judgment, to achieve intelligent management of VIP status.

UnderstandExpireTimeThe meaning of the field

In the security CMS user group management and VIP system,ExpireTimeThe field usually records the specific expiration time of VIP services.This field does not store a common readable date string, but a Unix timestamp (usually a 10-digit integer), which represents the number of seconds from 00:00:00 on January 1, 1970 (UTC/GMT) to the specified date and time.This storage method facilitates time calculation and comparison for the system, but when displayed on the front end, we need to convert it into a user-friendly date format.

UsestampToDateLabel for date formatting

AnQi CMS providesstampToDateTags used to convert Unix timestamps to various readable date and time formats. It is used in a straightforward and concise manner:

{{ stampToDate(时间戳, "格式") }}

Among them,时间戳it is the number we get fromExpireTimethe field.格式Then follow the Golang (AnQiCMS's development language) standard time formatting string. Golang's time formatting is not like PHP or Java usingY-m-dInstead of using placeholders like 'such as', a specific reference time point is used to define the format,“2006-01-02 15:04:05.999999999 -0700 MST”You only need to write the corresponding part of this reference time to get the desired format.

For demonstration purposes, let's assume you have already passeduserDetailLabel retrieved the current user's VIP information and assigned it touserProfileVariable:

{% set rawExpireTime = userProfile.ExpireTime %} {# rawExpireTime现在是原始的Unix时间戳 #}

<p>原始到期时间戳:{{ rawExpireTime }}</p>

<p>仅显示到期日期:{{ stampToDate(rawExpireTime, "2006年01月02日") }}</p>
{# 结果示例:2024年09月30日 #}

<p>显示精确到秒的到期时间:{{ stampToDate(rawExpireTime, "2006-01-02 15:04:05") }}</p>
{# 结果示例:20