PHP
date()
function
This section has a running instance and details the syntax and parameters of the date() function to help you familiarize yourself with the use of the date() function!
PHP Date/Time Reference Manual
Format the local date and time and return the formatted date string:
<?php
// Prints the day
echo date("l") . "<br>";
// Prints the day, date, month, year, time, AM or PM
echo date("l jS of F Y h:i:s A");
?>
Run an instance . . .
Definitions and usages
The date() function formats the local date and time and returns the formatted date string.
Grammar
parameter
|
describe
|
format
|
Required.Specify the format of the output date string.You can use the following characters:
-
D - the first few days in a month (from 01 to 31)
-
D - the text representation of the week (expressed in three letters)
-
J - a few days in a month, no front guide zero (1 to 31)
-
l ('L''s lowercase form) - a complete text of the week
-
N - Week's ISO-8601 digital format representation (1 means Monday [Monday], 7 means Sunday [Sunday])
-
S - English order suffix in the first few days (2 characters: ST, ND, RD or TH. With J
-
W - Digital representation of the week (0 indicates Sunday [Sunday], 6 means Saturday [Saturday])
-
Z - the first few days in the year (from 0 to 365)
-
W - use ISO-8601 digital format to represent the number of weeks in the year (starting from Monday from Monday) every week)
-
F - Month's Complete Text Expression (January [January] to December [December])
-
M - Month number representation (from 01 to 12)
-
M - Month's short text representation (expressed with three letters)
-
N - Month Number representation, no front guide zero (1 to 12)
-
T - given the number included in the month
-
L - whether it is a leap year (if it is a leap year, it is 0)
-
O - year numbers under ISO-8601 standard
-
Y - four-digit representation
-
Y - Two digits of the year
-
A - lowercase form: AM or PM
-
A - uppercase form: AM or PM
-
B - SWATCH Internet Time (000 to 999)
-
G - 12 hours, no front guide zero (1 to 12)
-
G - 24 hours, no front guide zero (0 to 23)
-
H - 12 hours, with preamble zero (01 to 12)
-
H - 24-hour system, front guide zero (00 to 23)
-
i - points, front guide zero (00 to 59)
-
s - second, with a front guide zero (00 to 59)
-
U - microseconds (new in PHP 5.2.2)
-
E - Time zone identifier (for example: UTC, GMT, Atlantic / Azores)
-
I (the uppercase form of i) - whether the date is in summertime (if it is daylight saving time, otherwise 0)
-
O - Greenwich Time (GMT) difference, unit is an hour (example: +0100)
-
P - Greenwich Time (GMT) difference, unit is Hours: minutes (new in php 5.1.3)
-
T - Time zone's shorthand (instance: EST, MDT)
-
Z - at a second unit offset.UTC is negatively negative in the west time zone (-43200 to 50400)
-
C - ISO-8601 standard dates (for example, 2013-05-05T16: 34: 42 + 00: 00)
-
R - RFC 2822 Format Date (for example, Fri, 12 APR 2013 12:01:05 +0200)
-
U - Since the number of seconds since UNIX Era (January 1 1970 00:00:00 GMT)
At the same time, the following predefined constants can also be used (available from php 5.1.0):
-
Date_atom - Atom (for example: 2013-04-12t15: 52: 01 + 00: 00)
-
Date_cookie - http cookies (for example: Friday, 12-APR-13 15:52:01 UTC)
-
Date_iso8601 - ISO-8601 (for example: 2013-04-12t15: 52: 01 + 0000)
-
Date_RFC822 - RFC 822 (for example: Fri, 12 APR 13 15:52:01 +0000)
-
Date_rfc850 - RFC 850 (eg, Friday, 12-APR-13 15:52:01 UTC)
-
Date_rfc1036 - RFC 1036 (for example: Fri, 12 APR 13 15:52:01 +0000)
-
Date_rfc1123 - RFC 1123 (for example: Fri, 12 APR 2013 15:52:01 +0000)
-
DATE_RFC2822 - RFC 2822(Fri, 12 Apr 2013 15:52:01 +0000)
-
Date_rfc3339 - the same as Date_atom (starting from PHP 5.1.3)
-
DATE_RSS - RSS(Fri, 12 Aug 2013 15:52:01 +0000)
-
Date_W3C - World Wide Web Alliance (for example: 2013-04-12t15: 52: 01 + 00: 00)
|
timestamp
|
Optional.Specifies an integer UNIX timestamp.The default is the current local time (time ()).
|
Technical details
Return value:
|
If successful, the formatted date string is returned, and if it fails, E_WARNING error and false.
|
PHP version:
|
4+
|
Update log:
|
PHP 5.1.0: New E_STRICT and E_NOTICE time zone errors. T
he timestamp for the valid range is from Friday, December 13, 1901 at 20:45:54 GMT to Tuesday, January 19, 2038 at 03:14:07 GMT.
In versions prior to 5.1.0, timestamps on some systems, such as Windows, were limited from 01-01-1970 to 19-01-2038.
PHP 5.1.1: New standard date/time format constant to specify the format parameter.
|
PHP Date/Time Reference Manual