Have you wanted to dynamically output the date or the
current time on your webpage? Well now you can. Everytime
a visitor loads your page, it can output the current date/time.
This function returns the current, local date and time, formatted
according to your wishes. What you pass into the function is a cryptic-looking
string of characters that are actually codes for formatting the date/time.
Special formatting character | Explaination | Example of what this produces (Using this server's current time and date) (Tue, 19 Mar 2024 06:13:57 -0400) |
a | Lowercase Ante meridiem or Post meridiem | am |
A | Uppercase Ante meridiem or Post meridiem | AM |
B | Swatch Internet time (Whatever that is) | 468 |
d | Day of the month in 2 digits with leading zeros | 19 |
D | A three-letter abbreviation for the day | Tue |
F | The month, written out. | March |
g | 12-hour format of the hour without leading zeros | 6 |
G | 24-hour format of the hour without leading zeros | 6 |
h | 12-hour format of the hour with leading zeros | 06 |
H | 24-hour format of the hour with leading zeros | 06 |
i | Minutes with leading zeros | 13 |
I | This is an uppercase i. 1 if we are in Daylight Savings Time, 0 if Standard time. | 1 |
j | Day of the month without leading zeros | 19 |
l | This is a lowercase L. The day of the week, written out | Tuesday |
L | 1 if it's a leap year, 0 if it's not. | 1 |
m | Month of the year as a number, with leading zeros | 03 |
M | A three-letter abbreviation for the month | Mar |
n | Month of the year as a number, without leading zeros | 3 |
O | Difference in hours from Greenwich time (GMT) to local time | -0400 |
r | The current date in the RFC 822 format | Tue, 19 Mar 2024 06:13:57 -0400 |
s | Seconds, with leading zeros | 57 |
S | English ordinal suffix for the day of the month, these would be: st, nd, rd or th. It's common to use this along with j formatter | th |
jS | Just an example of calling jS together ie:
<?php echo date('jS'); ?>
| 19th |
t | Number of days in the given month | 31 |
T | Timezone setting of this computer | EDT |
U | Seconds since the Unix Epoch which is January 1 1970 00:00:00 GMT. | 1710843237 |
| The U is the same as calling the time() function | 1710843237 |
w | The day of the week as a number. Starts at Sunday with 0 and ends with Saturday being a 6 | 2 |
W | Week of the year, using the ISO-8601 standard (weeks starting on Monday) (Must have PHP 4.1.0 or higher) | 12 |
Y | The year in 4 digits | 2024 |
y | The year in 2 digits | 24 |
z | The current day of the year | 78 |
Z | Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. | -14400 |
This function returns the number of seconds since the Unix Epoch which is January 1 1970 00:00:00 GMT. It is the same as calling the
date()
function with the U
formatter.