WordPress custom time display format_PHP tutorial

WBOY
Release: 2016-07-13 09:59:42
Original
975 people have browsed it

WordPress custom time display format

This article mainly introduces the method of WordPress customizing the time display format. Friends who need it can refer to it

I’m helping King change the template of his private couple blog~ I searched a lot and finally got the time displayed in the format I want. So I wrote down some of the information I obtained for memo and reference by friends.

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

1. the_date_xml() function

Call format:

The code is as follows:


Output format: YYYY-MM-DD

For example: 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_date() function only displays the first reference. In this case, it is best to use the_time() function. See: http://codex.wordpress.org/Template_Tags/the_date

Call format:

The code is as follows:


Parameter table:

format: (String type) Parameter that defines the time and date format.
before: (String type) Text placed before the date, no default value.
after: (String type) Text placed after the date, no default value.
echo: (Boolean) Display the date (TRUE), or return the date for use by PHP (FALSE). The default value is TRUE.

3. the_time() function

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

Call format:

The code is as follows:


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

Parameter table:

format: (String type) Parameter that defines the time and date format.

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 within a loop. See: http://codex.wordpress.org/Template_Tags/get_the_time

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

Parameter table:

format: (String type) Parameter that defines the time and date format.
The values ​​that can be used for the format parameters of the above three functions:

a = Generally used when displaying in 12-hour format, showing that the current time is am (morning) or pm (afternoon) A = The function is the same as above, the difference is that am or pm is capitalized

d = day of January, always displayed as two digits

F = month represented by the full name of the text

g = The number of hours in 12-hour format, the number of digits is determined based on the actual time G = The number of hours in the 24-hour format, the number of digits is determined based on the actual time

h = hour in 12-hour format, always displayed in two digits H = hour in 24-hour format, always displayed in two digits

Note: If the current time is 8 o'clock in the morning, the output result using the h parameter is 08, and the output result using the g parameter is 8. Changing to uppercase only changes the time system.

i = Current minute I = Output a zero, I don’t know what it is used for, I hope someone who knows can give me some advice. (capital i)

j = day of January, the number of digits is determined based on the actual date

l = Day of the week expressed in text (lowercase L) L = Output a zero. I don’t know what it is used for. I hope brothers who know it can give me some advice.

m = Month represented by number M = Month expressed by English abbreviation

s = current seconds S = generally used with parameter j, the effect is to add an ordinal word after the number of days (st, nd, rd, etc.)

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

Note: Parameters are case-sensitive. Non-parameter characters written within parameter quotes are not processed and are output directly.

For example, the following format string:

l, F j, Y

will generate a date in the following format:

Friday, September 24, 2004

5. single_month_title() function

Call format:

The code is as follows:


Parameter table:

prefix: prefix of year and month
Output format: prefix MONTH prefix YEAR

If the prefix parameter is "*", the displayed result will be as follows:

*February * 2004

The time function finally changed for King is the_time('Y year m month d day, H hour s minute i second') The display effect is: Published on: June 12, 2010, 23:14:32

Everyone can draw inferences from one example. Find the effect you want

The above is the entire content of this article. I hope it will be helpful to everyone learning WordPress.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/975135.htmlTechArticleWordPress custom time display format This article mainly introduces the method of WordPress customizing the time display format, friends who need it You can refer to the following to help King change his private couple blog template...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template