The AnQi CMS实战: Display VIP membership expiration dates elegantly in the user center, say goodbye to timestamp troubles!

In modern content operation, the VIP membership system is an important factor in enhancing user stickiness and achieving content monetization.Anqi CMS with its flexible user group management and VIP system allows you to easily build paid content or membership services.However, how to promote VIP members'ExpireTime(Due date) should be displayed to users in an intuitive and easy-to-understand manner, avoiding confusion caused by raw timestamps, which is crucial for improving user experience. Today, we will delve into how to cleverly utilize it in the user center of Anqi CMS.stampToDateTemplate tags make the expiration date of VIP members clear at a glance.

VIP MemberExpireTimeBehind the Scenes: Understanding Timestamps

First, let's understand the VIP members in Anqi CMS.ExpireTime. In the Anqi CMS backend user management, when you set a VIP membership qualification for a user, the system records an expiration time. ThisExpireTimeThe field typically stores a Unix timestamp (Unix Timestamp), which is the number of seconds elapsed since 00:00:00 UTC on January 1, 1970.For the system, a timestamp is an efficient way to store and calculate time, but for users, a string of pure numbers as a timestamp is obviously not friendly. They would rather see specific dates and times like

Anqi CMS passeduserDetailTemplate tags can conveniently obtain various details of the current user, including VIP members' informationExpireTime. In the user center's custom template, you can get the user'sExpireTime.

stampToDate: Time formatting wizard

In order to convert the original Unix timestamp into the familiar date and time format, AnQi CMS provides a very practical template tag -stampToDateThis tag is like a time formatting wizard, which can instantly transform a timestamp into a clear and readable date string with just the specified format.

stampToDateThe syntax of the tag is very intuitive:{{stampToDate(时间戳, "格式")}}. The 'timestamp' here is the number we obtained fromuserDetailObtained from the tagExpireTimeWhile the "format" follows the Go language standard library's date formatting rules. For operators unfamiliar with Go language date formats, this may sound abstract, but in fact, you just need to remember some commonly used "magic number" combinations:

  • “2006-01-02”: Will format the timestamp as "YYYY-MM-DD", for example "2023-12-31".
  • “January 2, 2006”: Format as 'Year 01/02', for example '2023 December 31'.
  • “15:04:05”: Format as 'HH:mm:ss', for example '14:30:59'.
  • '2006-01-02 15:04': Combine the date and time, for example, '2023-12-31 14:30'.

With these, you can flexibly display the date format according to the page requirements.

Practice session: Display VIP expiration date in the user center

Now, let's put the theory into practice and see how to display on the user center page (usually template/您的模板目录/user/profile.htmlor