您好,登录后才能下订单哦!
今天就跟大家聊聊有关使用PHP怎么获取本周的第一天和最后一天,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
//本周的第一天和最后一天 
复制代码 代码如下:
$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'); 
经过测试modity不知道是用做什么了,于时找了另两个例子 
复制代码 代码如下:
//这个星期的星期一 
// @$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]; 
} 
//这个星期的星期天 
复制代码 代码如下:
// @$timestamp ,某个星期的某一个时间戳,默认为当前时间 
// @is_return_timestamp ,是否返回时间戳,否则返回时间格式 
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]; 
} 
看完上述内容,你们对使用PHP怎么获取本周的第一天和最后一天有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。