WordPress commonly used time and date format function using the method

Source: Internet
Author: User
Tags echo date time and date

In the use of WordPress process, often need to format the date of WordPress, in PHP format or Date function is date (), but in WordPress using the The_time () function to format the WordPress time and date, Their usage is essentially the same, but The_time () is the direct output, and the date () function is the return time string.

Parameter description

Parameter parameter description output time format
D Date 06
J Date 6
D Monday
F Month January
G-hour 6
G-hour 06
H minutes 6
H minutes 06
A last afternoon am/pm
A last Afternoon am/pm
L Monday Week
M month 01
M months of the month
N Month 6
O Time Zone +0800
R Full Date Time Mon 2010 20:30:10 +0800
Suffix st/th of S-sequence numbers
T Time Zone CST
W Week 2
W Week number 22
Y Year 10
Y Year 2010
Z Days 365

Using the sample

Chinese date format setting, Month Day: such as: February 1, 2010

The_time (' Y year n Month J Day ');

Chinese time setting, Hours: 22:22:22

The_time (' g:i:s ');

Week format setting, week: Thursday, November 1, 2010

The_time (' Y year n month J Day L ');

Of course, sometimes our theme like Chinese and English mixed date display format, for the use of WordPress, this will make some small adjustments. Here, for example, the month in which the log time is displayed, we use The_time (' M ') in the topic to print out the English abbreviated month value for a Sep.

But fortunately and unfortunately, WordPress will be very humane for you to translate into nine, said lucky because of the intelligent WordPress people feel happy, said unfortunately because I really need Sep such as the English shorthand format, which let me how to be good.

So how do we do this at this time, from the function point of view to solve this problem, reset to avoid the Chinese. The function:

The_time (' M ');

Replace with:

echo Date (' M ', get_the_time (' U '));

This time we find that we have the time format we need.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.