The first and last day of the week
Copy CodeThe code is as follows:
$date =new DateTime ();
$date->modify (' this week ');
$first _day_of_week= $date->format (' y-m-d ');
$date->modify (' This week +6 days ');
$end _day_of_week= $date->format (' y-m-d ');
After testing modity do not know what to do, in the time to find another two examples
Copy CodeThe code is as follows:
This week's Monday
@ $timestamp, a certain time stamp of a certain week, default to the current time
@is_return_timestamp whether the timestamp is returned, otherwise the time format is returned
function This_monday ($timestamp =0, $is _return_timestamp=true) {
Static $cache;
$id = $timestamp. $is _return_timestamp;
if (!isset ($cache [$id])) {
if (! $timestamp) $timestamp = time ();
$monday _date = Date (' y-m-d ', $timestamp -86400*date (' W ', $timestamp) + (date (' W ', $timestamp) >0?86400:-/*6*86400*/ 518400));
if ($is _return_timestamp) {
$cache [$id] = Strtotime ($monday _date);
}else{
$cache [$id] = $monday _date;
}
}
return $cache [$id];
}
This Sunday of the week
Copy CodeThe code is as follows:
@ $timestamp, a certain time stamp of a certain week, default to the current time
@is_return_timestamp whether the timestamp is returned, otherwise the time format is returned
function This_sunday ($timestamp =0, $is _return_timestamp=true) {
Static $cache;
$id = $timestamp. $is _return_timestamp;
if (!isset ($cache [$id])) {
if (! $timestamp) $timestamp = time ();
$sunday = This_monday ($timestamp) +/*6*86400*/518400;
if ($is _return_timestamp) {
$cache [$id] = $sunday;
}else{
$cache [$id] = date (' y-m-d ', $sunday);
}
}
return $cache [$id];
}
http://www.bkjia.com/PHPjc/825315.html www.bkjia.com true http://www.bkjia.com/PHPjc/825315.html techarticle //The first day of the week and the last day copy the code code as follows: $date =new DateTime (); $date-modify (' this week '); $first _day_of_week= $date-format (' y-m-d ' ); $date-modify (' This week +6 ...