1. Overview of the getdate function arraygetdate ([int $ timestamptime ()]) function: Get date/time information description: returns a result based on & nbsp; timestamp & nbsp; the resulting associated array & nbsp; array containing date information. If no timestamp is provided, it is regarded as the current local time. Parameter 1. getdate function overview
array getdate ([ int $timestamp = time() ] )
Function: Get date/time information
Description: A result is returned?timestamp
? Is the resulting correlated array containing date information? Array. If no timestamp is provided, it is regarded as the current local time.
Parameter: optional?timestamp
? The parameter is? Integer? If not specified, the parameter value defaults to the current local time. That is to say, the default value is? Time ()? .
Return value: returns a result according?timestamp
? Is the resulting correlated array containing date information? Array. The key list elements in the returned joined array include the following:
Example #1?Getdate ()? Example
Output result:
Array( [seconds] => 40 [minutes] => 58 [hours] => 21 [mday] => 17 [wday] => 2 [mon] => 6 [year] => 2003 [yday] => 167 [weekday] => Tuesday [month] => June [0] => 1055901520)
II. example: use getdate to determine whether two dates are the same day or two consecutive days
Note: The strtotime function converts formatted date strings to corresponding Unix timestamps.
Example #2 demo code
$ Date1 = getdate (strtotime ('2017-12-31 '); $ date11 = getdate (strtotime ('2017-01-01 ')); $ date2 = getdate (strtotime ('1970-12-31 '); print_r ($ date1); echo "\ n"; print_r ($ date2); echo "\ n "; // judge whether two days are connected to function isStreakDays ($ last_date, $ this_date) {if ($ last_date ['Year'] ===$ this_date ['Year']) & ($ this_date ['yday']-$ last_date ['yday'] = 1) {return TURE ;} elseif ($ this_date ['Year']-$ last_date ['Year'] = 1) & ($ last_date ['mon']-$ this_date ['mon'] = 11) & ($ last_date ['mday']-$ this_date ['mday'] = 30) {return TURE;} else {return FALSE ;}} // Determine whether the two days are the same day function isDiffDays ($ last_date, $ this_date) {if ($ last_date ['Year'] ===$ this_date ['Year']) & ($ this_date ['yday'] ===$ last_date ['yday']) {return FALSE;} else {return TRUE ;}} if (isStreakDays ($ date1, $ date11) {echo "2013-12-31 and 2014-01-01 are two consecutive days \ n";} if (isDiffDays ($ date1, $ date2 )) {echo "2013-12-31 and 2012-12-31 are not the same day \ n ";}
Output result:
Array ([seconds] => 0 [minutes] => 0 [hours] => 0 [mday] => 31 [wday] => 2 [mon] => 12 [year] => 2013 [yday] => 364 [weekday] => Tuesday [month] => December [0] => 1388419200) array ([seconds] => 0 [minutes] => 0 [hours] => 0 [mday] => 31 [wday] => 1 [mon] => 12 [year] => 2012 [yday] => 365 [weekday] => Monday [month] => December [0] => 1356883200) and are two consecutive days, and are not the same day
If you have any questions, please feel free to discuss them with me in the reply below.