$ts = time(); |
$last_monday = last_monday( $ts ); |
echo date ( 'Y-m-d H:i:s' , $last_monday ); |
//上周一 |
// @$timestamp ,某个星期的某一个时间戳,默认为当前时间 |
// @is_return_timestamp ,是否返回时间戳,否则返回时间格式 |
function last_monday( $timestamp =0, $is_return_timestamp =true){ |
static $cache ; |
$id = $timestamp . $is_return_timestamp ; |
if (!isset( $cache [ $id ])){ |
if (! $timestamp ) $timestamp = time(); |
$thismonday = this_monday( $timestamp ) - /*7*86400*/ 604800; |
if ( $is_return_timestamp ){ |
$cache [ $id ] = $thismonday ; |
} else { |
$cache [ $id ] = date ( 'Y-m-d' , $thismonday ); |
} |
} |
return $cache [ $id ]; |
} |