A-A+

php实现获取本周一、本周五的日期

2014年03月13日 PHP 暂无评论 阅读 7,431 views 次

//获取本周周一
 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];
 }

标签:

给我留言

Copyright © 严佳冬 保留所有权利.   Theme  Ality 百度地图 苏ICP备19045515号-2

用户登录

分享到: