PHP format display time date function


Format time

##The date() function is used to format the time and return a string.


string date( string format [, int timestamp] )

The parameter format indicates the method of time format. The possible methods are as follows:

Format Description:
Formatting method Explain
Y Four digit year, y is two digit year, such as 1999
m Number month, with leading 0 in front, such as 01. N is the zero digit month without leading
F Month, full text format, such as January or March
M A three letter abbreviation for a month, such as Jan or mar
d On the day of the month, there is a leading 0, such as 03. J is the number of days without leading 0
w The day of the week, in numbers, 0 for Sunday
z Day of year, range 0-366
W The week of the year, such as week 32
H 24-hour format, leading 0, h is 12 hour format
G 24-hour format, no leading 0, G is the corresponding 12-hour format
i Minute format, leading 0
s Second format with leading 0
A Uppercase afternoon, such as am, a is lowercase

The optional parameter timestamp represents the time stamp, which is the current time stamp by default.

We can display the required time and date through the rich format provided by the date() function, as shown in the following example:

Date ("y-m-d, time()); // the display format is as follows: 2008-12-01
Date ("y.m.d, time()); // the display format is as follows: December 1, 2008
Date ("M D Y", time()); // the display format is Dec 01 2008.
Date ("y-m-d H: I, time()); // the display format is as follows: 2008-12-01 12:01


If the time difference between the output time and the actual time is 8 hours (assuming that you use the Beijing time zone), please check the php.ini file and make the following settings:

date.timezone = PRC

For other time zone settings, please refer to: