PHP獲取本周第一天和最后一天示例代碼
更新時間:2014年02月24日 11:41:14 作者:
這篇文章主要介紹了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');
經(jīng)過測試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];
}
復制代碼 代碼如下:
$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');
經(jīng)過測試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返回當前日期或者指定日期是周幾
- PHP獲取當前日期和時間及格式化方法參數(shù)
- PHP使用GETDATE獲取當前日期時間作為一個關聯(lián)數(shù)組的方法
- PHP獲取當前日期所在星期(月份)的開始日期與結束日期(實現(xiàn)代碼)
- php、mysql查詢當天,查詢本周,查詢本月的數(shù)據(jù)實例(字段是時間戳)
- php獲取本周星期一具體日期的方法
- php獲取本周開始日期和結束日期的方法
- 用php獲取本周,上周,本月,上月,本季度日期的代碼
- PHP實現(xiàn)今天是星期幾的幾種寫法
- PHP計算一年多少個星期和每周的開始和結束日期
- PHP獲取一年中每個星期的開始和結束日期的方法
- PHP獲取當前日期及本周一是幾月幾號的方法
相關文章
PHP采集靜態(tài)頁面并把頁面css,img,js保存的方法
這篇文章主要介紹了PHP采集靜態(tài)頁面并把頁面css,img,js保存的方法,可以實現(xiàn)簡單的網(wǎng)頁抓取功能,具有一定的參考借鑒價值,需要的朋友可以參考下2014-12-12PHP合并數(shù)組函數(shù)array_merge用法分析
這篇文章主要介紹了PHP合并數(shù)組函數(shù)array_merge用法,結合實例形式分析了php數(shù)組合并函數(shù)array_merge的具體功能、使用方法與相關注意事項,需要的朋友可以參考下2017-02-02