手机
当前位置:查字典教程网 >编程开发 >php教程 >PHP获取本周第一天和最后一天示例代码
PHP获取本周第一天和最后一天示例代码
摘要://本周的第一天和最后一天复制代码代码如下:$date=newDateTime();$date->modify('thisweek');$f...

//本周的第一天和最后一天

复制代码 代码如下:

$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获取本周第一天和最后一天示例代码】相关文章:

PHP生成器简单实例

php获取网页里所有图片并存入数组的方法

PHP脚本的10个技巧(8)

PHP程序员使用最多的五个工具

PHP教程:清除wordpress里恶意代码

PHP脚本的10个技巧(4)

PHP自动生成月历代码

PHP脚本的10个技巧(6)

写一段简单的PHP建立文件夹代码

PHP脚本的10个技巧(7)

精品推荐
分类导航