How to use the `stampToDate` tag for date formatting and conditional judgment for the `ExpireTime` (VIP expiration time) field?

Calendar 👁️ 68

In the daily operation of Anqi CMS, we often need to handle time-related fields, such as the expiration time of the user's VIP (ExpireTime)。Correctly display these time information, and make flexible conditional judgments according to their status, which is crucial for improving user experience and implementing personalized content display. This article will focus onExpireTimefield, discuss in detail how to utilizestampToDatetag for date formatting, combined with conditional judgment, to implement intelligent management of VIP status.

UnderstandingExpireTimethe meaning of the field

In the Anqi 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 UTC/GMT on January 1, 1970 to the specified date and time.This storage method is convenient for the system to perform time calculation and comparison, but when displayed on the front-end, we need to convert it to a user-friendly date format.

UsestampToDatetag for date formatting

AnQi CMS providesstampToDateThe tag is specifically used to convert Unix timestamps into various readable date and time formats. Its usage is intuitive and concise:

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

Among them,时间戳which we get fromExpireTimethe field, and格式It follows the standard time formatting string of Golang (the development language of AnQiCMS). Golang's time formatting is not like PHP or Java.Y-m-dIt is the point in time at which the format is defined instead of using a placeholder, that is“2006-01-02 15:04:05.999999999 -0700 MST”. You just need to write according to the corresponding part of this reference time and you will get the format you want.

For demonstration purposes, we assume that you have already passed.userDetailThe label obtained the current user's VIP information and assigned it touserProfileVariable:

`twig {% userDetail userProfile with id=currentUser.Id %} {# Assume currentUser.Id is the current user's ID #}

{% 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

Related articles

How to retrieve and display the user's exclusive `InviteCode` (invitation code) with the `userDetail` tag?

In AnQiCMS, if you want to display users' exclusive invitation codes on the website page, this usually involves the application of the membership system or referral mechanism.AnQiCMS provides flexible template tags that can help us easily obtain and display various user information, including invitation codes (`InviteCode`). To implement this feature, we mainly use the AnQiCMS `userDetail` tag.

2025-11-07

How to display the personal introduction filled in the `Introduce` field on the user's profile page?

In website operation, providing users with personalized profile display, especially the personal introduction filled in by users themselves, can greatly enhance the vitality and sense of belonging of the community.For users of AnQiCMS, it is actually a very intuitive and flexible operation to display the personal introduction filled in by the user in the `Introduce` field on the profile page, mainly relying on the powerful template tag system of AnQiCMS.### Understand the template mechanism of AnQiCMS In AnQiCMS

2025-11-07

How to get the `GroupId` of the user through the `userDetail` tag and further get the detailed information of the user group?

In AnQiCMS, providing personalized content and experience to users is a key link to enhance website stickiness.It is particularly important to understand the details of the user's group to display exclusive content based on user level or provide differentiated service information.Today, let's delve into how to make use of the powerful template tag features of AnQiCMS, through the `userDetail` tag to obtain the `GroupId` of the user, and further use the `userGroupDetail` tag to display the detailed information of these user groups on the website front end

2025-11-07

How to use `AvatarURL` or `FullAvatarURL` to display a user avatar in the template?

In website operation, the user avatar is not just a decoration, it carries the user's identity and is an important part of community interaction and personalized experience.Whether it is in the comment area, author introduction, or member center, a clear user avatar can significantly enhance the website's affinity and professionalism.AnQiCMS as an efficient content management system naturally also provides us with the powerful function of flexibly displaying user avatars in templates.Today, let's talk about how to use the `AvatarURL` and `FullAvatarURL` fields in AnQiCMS templates

2025-11-07

How to determine the user's VIP status based on `ExpireTime` in the template and display an expiration reminder or renewal option?

When operating your website, if you provide membership or VIP services, it is crucial for users to clearly understand their VIP status, when it will expire, and how to renew it, as this is essential for improving user experience and member retention.AnQiCMS (AnQiCMS) leverages its flexible template engine and powerful user management features, allowing you to easily implement these functions in website templates.We all know that Anqi CMS is built with a comprehensive user group management and VIP system, which allows us to conveniently set different levels of user permissions and paid content.

2025-11-07

What is the specific function of the `Link` generated by the `userDetail` tag, and how to use it correctly?

AnQi CMS is an efficient and flexible content management system, with its powerful template tag function as the core of dynamic content display.In the daily operation of websites, we often need to display information related to users, such as article authors, member homepages, and so on.At this point, the `userDetail` tag comes into play, and what is particularly crucial is the `Link` (user link) field it generates.

2025-11-07

How to use the `siteId` parameter to call user detail data across sites in multi-site management?

In the multi-site management of AnQi CMS, efficiently sharing and accessing data is the key to improving operational efficiency.Especially in the user system, sometimes we need to display or utilize user details from another site, such as a unified user center, cross-site member privilege display, etc.At this time, the `siteId` parameter provided by AnQi CMS has become a powerful bridge to connect user data across different sites.

2025-11-07

How to use the `userGroupDetail` tag to retrieve and display the `Id` (ID) of a specified user group?

In AnQi CMS, sometimes we may need to retrieve and display the unique identifier (ID) of a specific user group, such as for conditional judgment in templates, or adjusting page content based on user group ID.The `userGroupDetail` tag provided by AnQi CMS makes it convenient for us to easily obtain detailed information about user groups, including their ID.User group management is one of the core features of Anqicms, which allows us to group users and define different permission levels, even supporting paid content and membership services.

2025-11-07