$ts = time(); |
$this_monday = this_monday( $ts ); |
echo date ( 'Y-m-d H:i:s' , $this_monday ); |
//这个星期的星期一 |
// @$timestamp ,某个星期的某一个时间戳,默认为当前时间 |
// @is_return_timestamp ,是否返回时间戳,否则返回时间格式 |
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 ]; |
|
} |