PHP date
PHP date() function is used to format time/date.
PHP date() function
PHP date() function can format the timestamp into a more readable date and time.
A timestamp is a character sequence that represents the date/time when a certain event occurred.
Syntax
string date ( string $format [, int $timestamp ] )
Description | |||
---|---|---|---|
Required. Specifies the format of the timestamp. | |||
Optional. Specify timestamp. The default is the current date and time. |
format characters | Description | Return value example | |
---|---|---|---|
日 | --- | --- | |
d | Day of the month, 2 digits with leading zero | 01 To 31 | |
D | The day of the week, text indicates , 3 letters | Mon to Sun | |
##j | month Days in , without leading zeros1 to 31 | ||
l( Lowercase "L") | Day of the week, complete text formatSunday to Saturday | ||
N | #Day of the week represented by numbers in ISO-8601 format (newly added in PHP 5.1.0)1 (meaning Monday) to 7 (meaning Sunday) | ||
S | The English suffix after the number of days in a month, 2 charactersst, nd, rd or th. You can use | ||
## together with j. The number represents the day of the week. | 0 | (meaning Sunday) to 6 (meaning Saturday) | |
in the year The days from | 0 | to 365 | |
--- | ---|||
ISO-8601 format Week number in year, weekly Starting from Monday (new in PHP 4.1.0) | For example:42 | (the 42nd week of the year)||
--- | ---##F | ||
month, complete Text format, such as January or March | Januaryto | December##m | |
01 | to12 | M | |
Jan | toDec | n | |
1 | to12 | ##t | |
28 to | 31年 | ||
--- | L | ||
If it is a leap year, it is1, otherwise it is | 0o | ||
except if ISO If the week number (W) of belongs to the previous year or the next year, use that year.(New in PHP 5.1.0) | Examples: 1999 or 2003 | ||
##Y | A complete year represented by 4 digitsFor example: | 1999 or 2003 | |
y | 2-digit yearFor example: | 99 or 03 | |
--- | --- | ||
Lowercase AM and PM values | am | orpm | ##A|
Capitalized AM and PM values | AMor | PM##B | |
000 | to999 | ##g | |
1 to | 12G | ||
0 to | 23h | ||
01 to | 12##H | Hour, 24 hour format, with leading zeros||
00 to 23 | i | Number of minutes with leading zeros||
00 to 59 | >s | Number of seconds with leading zeros||
00 to 59 | >u | milliseconds (new in PHP 5.2.2). It should be noted that the||
function always returns 000000 | because it only acceptsinteger parameters, and DateTime::format() only supports milliseconds. Example: 654321 | Time zone | ---|
e | Time zone identifier (newly added in PHP 5.1.0) | ||
UTC, GMT | ,Atlantic/Azores | ##IIs it daylight saving time | |
, otherwise it is 0 | OThe number of hours from Greenwich Mean Time | ||
##P | The difference from Greenwich Mean Time (GMT), there is a colon separating hours and minutes (newly added in PHP 5.1.3) | For example:||
T | The time zone where this machine is located | For example:||
MDT( 【Translator's Note】In Windows The complete text format is shown below, such as "Eastern Standard Time", the Chinese version will display "China Standard Time"). | ZThe number of seconds for the time difference offset. Time zone offsets west of UTC are always negative, and time zone offsets east of UTC are always positive. | -43200 To 43200 | |
Complete date/time | --- | --- | |
c | Date in ISO 8601 format (new in PHP 5) | 2004-02-12T15:19:21+00:00 | |
r | RFC 822 date format | Example:Thu, 21 Dec 2000 16:01:07 +0200 | |
#U | From Unix The number of seconds since the beginning of the epoch (January 1 1970 00:00:00 GMT)See | time() |
Complete PHP Date Reference Manual.
This reference manual provides a brief description and application examples of each function!