Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize the time display format of WordPress

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to customize the time display format of WordPress". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "WordPress how to customize the time display format" bar!

WordPress controls the output of time and date through a series of time and date functions. Here are some common functions:

1. The_date_xml () function

Call format:

The copy code is as follows:

Output format: YYYY-MM-DD

Such as: 2005-05-14

2. The_date () function

Description: this function is generally used to display time and date. According to the official documentation, when there are multiple archives published on the same day on a page, the the_date () function is displayed only at the first reference, in which case it is best to use the the_time () function. See: http://codex.wordpress.org/Template_Tags/the_date

Call format:

The copy code is as follows:

Parameter table:

Format: (string type) defines parameters in the format of time and date.

Before: (string) text placed before the date, with no default.

After: (string) text placed after the date, with no default.

Echo: (Boolean) displays the date (TRUE), or returns the date used by the PHP (FALSE). The default is TRUE.

3. The_time () function

Description: this function is used to display time and date. According to the official documentation, this function must be used within the loop. See: http://codex.wordpress.org/Template_Tags/the_time

Call format:

The copy code is as follows:

< ?php the_time('format'); ?>

Parameter table:

Format: (string type) defines parameters in the format of time and date.

4. Get_the_time () function

Note: according to the official documentation, this function only returns time information to PHP, does not display the time and date, and must be used in the loop. See: http://codex.wordpress.org/Template_Tags/get_the_time

Call format: php

< ?php get_the_time('format'); ?>

Parameter table:

Format: (string type) defines parameters in the format of time and date.

The values that can be used by the above three function format parameters:

A = generally used in 12-hour display, showing whether it is currently am (morning) or pm (afternoon) A = the function is the same as above, the difference is that am or pm is uppercase

D = which day of the month is always shown in double digits

F = the month indicated by the full name of the text

G = the number of hours in the 12-hour system, the number of digits is determined according to the actual time, G = the number of hours in the 24-hour system, and the number of digits is determined according to the actual time.

H = the number of hours in the 12-hour system, fixed in double digits to show the number of hours in the 24-hour system, and fixed in double digits

Note: if the current time is 8: 00 in the morning, the output result with h parameter is 08, the output result with g parameter is 8, and only change the timing after changing to uppercase.

I = current minutes I = output a zero, I do not know how to use, hope to know the brother's advice. (capital I)

J = which day of the month, the number of digits is determined according to the actual date

L = the week expressed in words (lowercase L) L = output a zero, I do not know how to use, hope to know the brother's advice.

M = numeric month M = abbreviated month

S = current seconds S = generally followed by the parameter j, the effect is to add ordinal words after days (st, nd, rd, etc.)

Y = 4-digit year y = 2-digit year

Note: parameters are case-sensitive. Non-parametric characters written in parameter quotation marks are output directly without processing.

For example, the following format string:

L, F j, Y

A date in the following format will be generated:

Friday, September 24, 2004

5. Single_month_title () function

Call format:

The copy code is as follows:

Parameter table:

Prefix: prefix of year and month

Output format: prefix + MONTH + prefix + YEAR

If the prefix parameter is "*", the result will look like the following:

* February * 2004

The final changed time function is the_time (m / d / Y, H / s / I / s). The display effect is: published on: June 12, 2010, 23:14:32

At this point, I believe you have a deeper understanding of "WordPress how to customize the time display format". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 267

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report