WordPress Date and Time Format Characters Explained
In WordPress development, you often need to format dates and times using functions like date_i18n() or get_the_date(). These functions use specific format characters to control the output. The table below explains the meaning and examples of these characters.
| Character | Description | Example Output |
|---|---|---|
| Day | ||
d |
Day of the month, 2 digits with leading zeros | 01 to 31 |
D |
A textual representation of a day, three letters | Mon through Sun |
j |
Day of the month without leading zeros | 1 to 31 |
l (lowercase 'L') |
A full textual representation of the day of the week | Sunday through Saturday |
N |
ISO-8601 numeric representation of the day of the week | 1 (Monday) to 7 (Sunday) |
S |
English ordinal suffix for the day of the month, 2 characters | st, nd, rd, th. Often used with j. |
w |
Numeric representation of the day of the week | 0 (Sunday) to 6 (Saturday) |
z |
The day of the year (starting from 0) | 0 to 365 |
| Week | ||
W |
ISO-8601 week number of year, weeks starting on Monday | e.g., 42 (the 42nd week in the year) |
| Month | ||
F |
A full textual representation of a month | January through December |
m |
Numeric representation of a month, with leading zeros | 01 through 12 |
M |
A short textual representation of a month, three letters | Jan through Dec |
n |
Numeric representation of a month, without leading zeros | 1 through 12 |
t |
Number of days in the given month | 28 through 31 |
| Year | ||
L |
Whether it's a leap year | 1 for leap year, 0 otherwise. |
o |
ISO-8601 week-numbering year. Similar to Y, but adjusted for ISO week number (W) |
e.g., 1999 or 2003 |
Y |
A full numeric representation of a year, 4 digits | e.g., 1999 or 2023 |
y |
A two digit representation of a year | e.g., 99 or 23 |
| Time | ||
a |
Lowercase Ante meridiem and Post meridiem | am or pm |
A |
Uppercase Ante meridiem and Post meridiem | AM or PM |
B |
Swatch Internet Time | 000 to 999 |
g |
12-hour format of an hour without leading zeros | 1 to 12 |
G |
24-hour format of an hour without leading zeros | 0 to 23 |
h |
12-hour format of an hour with leading zeros | 01 to 12 |
H |
24-hour format of an hour with leading zeros | 00 to 23 |
i |
Minutes with leading zeros | 00 to 59 |
s |
Seconds with leading zeros | 00 to 59 |
| Timezone | ||
e |
Timezone identifier | e.g., UTC, GMT, Asia/Shanghai |
I |
Whether or not the date is in daylight saving time | 1 if DST, 0 otherwise. |
O |
Difference to Greenwich time (GMT) in hours (no colon) | e.g., +0800 |
P |
Difference to Greenwich time (GMT) with colon between hours and minutes | e.g., +08:00 |
T |
Timezone abbreviation | e.g., CST, EST |
Z |
Timezone offset in seconds (negative for West, positive for East of UTC) | -43200 to 43200 |
| Full Date/Time | ||
c |
ISO 8601 date | e.g., 2023-10-27T14:30:00+08:00 |
r |
RFC 2822 / 822 formatted date | e.g., Fri, 27 Oct 2023 14:30:00 +0800 |
U |
Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) | Same as time() function return value. |
Usage Examples
In your WordPress theme or plugin, you can use these format characters like this:
<?php
// Output format like "2023年10月27日 Friday"
echo date_i18n( 'Y年n月j日 l' );
// In the loop, output format like "2023-10-27 14:30"
echo get_the_date( 'Y-m-d H:i' );
?>
Understanding these format characters allows you to flexibly control the display of dates and times in WordPress to meet various design and functional requirements.