国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

PHP獲取本周第一天和最后一天示例代碼

2024-05-04 23:21:33
字體:
來源:轉載
供稿:網(wǎng)友
//本周的第一天和最后一天

復制代碼 代碼如下:


$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];
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 常宁市| 常德市| 苍溪县| 炎陵县| 乌拉特中旗| 孟州市| 望江县| 清流县| 大埔区| 山东省| 云浮市| 尉犁县| 河津市| 天台县| 望江县| 宿迁市| 浮梁县| 鲁山县| 胶州市| 容城县| 城步| 丹巴县| 巴楚县| 嘉祥县| 高清| 墨竹工卡县| 永康市| 木里| 繁峙县| 遂宁市| 岗巴县| 天台县| 松江区| 巩义市| 资阳市| 凤翔县| 东海县| 湟中县| 新乡县| 宁南县| 鄂尔多斯市|