This article mainly introduces the php date formatting method. a user-defined function is used to analyze the date formatting output method in the form of an instance. it is a very practical technique, for more information about how to format a date in php, see the following example. Share it with you for your reference.
The specific implementation code is as follows:
The code is as follows:
Function ShowDate ($ flag = 0, $ timestr = NULL)
{
// Obtain the number of weeks
$ Warr = array (
"0" => Sunday,
"1" => Monday,
"2" => Tuesday,
"3" => Wednesday,
"4" => Thursday,
"5" => Friday,
"6" => Saturday
);
$ I = date ("w", $ timeStamp );
// Set the Beijing time and obtain the timestamp
Date_default_timezone_set ('prc ');
$ TimeStamp = NULL;
If ($ timestr)
$ TimeStamp = strtotime ($ timestr );
Else
$ TimeStamp = time ();
// Set the time display format
$ Ret1 = date ("Y, m, d, H: m: s", $ timeStamp). "". $ warr [$ I];
$ Ret2 = date ("Y-m-d H: m: s", $ timeStamp). "". $ warr [$ I];
$ Ret3 = date ("y/m/d", $ timeStamp );
$ Ret = $ ret1; // The first type is returned by default.
If ($ flag = 2)
$ Ret = $ ret2;
Else if ($ flag = 3)
$ Ret = $ ret3;
Return $ ret;
}
I hope this article will help you with PHP programming.