A-A+
php实现获取本周一、本周五的日期
//获取本周周一 function this_monday($timestamp=0,$is_return_timestamp=true){ static $cache ; $id = $timestamp.$is_return_timestamp; if(!isset($cache[$id])){ if(!$timestamp) $timestamp = time(); $time= $timestamp-24*3600*date('w',$timestamp)+(date('w',$timestamp)>0?86400:-6*86400); $monday_date = date('Y-m-d',$time); if($is_return_timestamp){ $cache[$id] = strtotime($monday_date); }else{ $cache[$id] = $monday_date; } } return $cache[$id]; } //获取本周周五 function this_friday($timestamp=0,$is_return_timestamp=true){ static $cache ; $id = $timestamp.$is_return_timestamp; if(!isset($cache[$id])){ if(!$timestamp) $timestamp = time(); $friday = this_monday($timestamp) + 4*86400; if($is_return_timestamp){ $cache[$id] = $friday ; }else{ $cache[$id] = date('Y-m-d',$friday); } } return $cache[$id]; } //获取本周周六 function this_saturday($timestamp=0,$is_return_timestamp=true){ static $cache ; $id = $timestamp.$is_return_timestamp; if(!isset($cache[$id])){ if(!$timestamp) $timestamp = time(); $saturday= this_monday($timestamp) + 5*86400; if($is_return_timestamp){ $cache[$id] = $saturday ; }else{ $cache[$id] = date('Y-m-d',$saturday); } } return $cache[$id]; }