WordPress custom time display format_PHP tutorial
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

You can view the WordPress front-end by logging into the dashboard and switching to the View Sites tab; automate the viewing process with a headless browser; installing the WordPress plugin to preview the front-end within the dashboard; viewing the front-end via a local URL (if WordPress is set locally).

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.
