PHP complete se...LOGIN
PHP complete self-study manual
author:php.cn  update time:2022-04-15 13:53:54

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.

TipA timestamp is a character sequence that represents the date/time when a certain event occurred.

Syntax

string date ( string $format [, int $timestamp ] )
##ParametersDescriptionformatRequired. Specifies the format of the timestamp. timestamp Optional. Specify timestamp. The default is the current date and time.

PHP Date() - Formatted date

The first required parameter of the date() function format specifies how to format the date/time.

Here are some available characters:

  • d - represents the day of the month (01 - 31)

  • m - represents the month (01 - 12)

  • Y - represents the year (four digits)

For more informationformat For a list of all characters available in parameters, please consult our PHP Date Reference Manual, date() function.

You can insert other characters between letters, such as "/", "." or "-", so that you can add additional formatting:

<?php
echo date("Y/m/d") . "<br>";
echo date("Y.m.d") . "<br>";
echo date("Y-m-d");
?>

The output of the above code looks like this:

2016/05/11<br>
2016.05.11<br>
2016-05-11
month Days in , without leading zeros Day of the week, complete text format #Day of the week represented by numbers in ISO-8601 format (newly added in PHP 5.1.0)The English suffix after the number of days in a month, 2 characters w0z0##week---WFor example: (the 42nd week of the year) Month---##FJanuaryDecember Numerical month, with leading zeros to Three-letter abbreviation for the month to Number of months, without leading zeros to The number of days in a given month 31---LWhether it is a leap year0ISO-8601 format year number. This is the same value as YA complete year represented by 4 digitsFor example: 2-digit year For example: ##Time##a or ##AAMPMSwatch Internet Standard Time to hour, 12 hour format, no leading zeros 12 Hour, 24 hour format, no leading zeros 23 hour, 12 hour format, with leading zeros 12 Hour, 24 hour format, with leading zeros Number of minutes with leading zeros> Number of seconds with leading zeros > milliseconds (new in PHP 5.2.2). It should be noted that the date() because it only accepts ---- --Time zone identifier (newly added in PHP 5.1.0)For example: , If it is daylight saving time, it is 1For example: +0200For example: +02:00For example: EST,From Unix The number of seconds since the beginning of the epoch (January 1 1970 00:00:00 GMT)See
The format string can recognize the string of the following format parameters
format charactersDescriptionReturn value example
------
dDay of the month, 2 digits with leading zero01 To 31
D The day of the week, text indicates , 3 letters Mon to Sun
##j1 to 31
l( Lowercase "L") Sunday to Saturday
N1 (meaning Monday) to 7 (meaning Sunday)
Sst, nd, rd or th. You can use
## together with j. The number represents the day of the week. (meaning Sunday) to 6 (meaning Saturday)
in the year The days from to 365
---
ISO-8601 format Week number in year, weekly Starting from Monday (new in PHP 4.1.0) 42
---
month, complete Text format, such as January or March to ##m
0112M
JanDec n
112##t
28 to
---
If it is a leap year, it is1, otherwise it is o
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 1999 or 2003
y99 or 03
------
Lowercase AM and PM values ​​ampm
Capitalized AM and PM values ​​ or ##B
000999##g
1 to G
0 to h
01 to ##H
00 to 23i
00 to 59s
00 to 59u
function always returns 000000integer ​​​​parameters, and DateTime::format() only supports milliseconds. Example: 654321Time zone
e
UTC, GMTAtlantic/Azores##IIs it daylight saving time
, otherwise it is 0OThe number of hours from Greenwich Mean Time
##PThe difference from Greenwich Mean Time (GMT), there is a colon separating hours and minutes (newly added in PHP 5.1.3)
TThe time zone where this machine is located
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------
cDate in ISO 8601 format (new in PHP 5)2004-02-12T15:19:21+00:00
rRFC 822 date format Example:Thu, 21 Dec 2000 16:01:07 +0200
#Utime()
Full PHP Date Reference Manual

For a complete reference manual for all date functions, please visit our

Complete PHP Date Reference Manual.

This reference manual provides a brief description and application examples of each function!