1. 程式人生 > >PHP獲得某天某星期某月的開始結束時間

PHP獲得某天某星期某月的開始結束時間

<?php
//13點代表[13,14) from_unixtime unix_timestamp
date_default_timezone_set('PRC');
echo strtotime(date('Y-m-d H:00:00')); //當時之初
echo strtotime(date('Y-m-d H:59:59')); //當時之末

echo strtotime(date('Y-m-d 00:00:00'));  //當日之初
echo strtotime(date('Y-m-d 23:59:59')); //當日之末


//獲得任意一天的開始時間,結束時間
function getDayBE($day) {
return array(strtotime($day), strtotime($day)+24*3600-1);
}


//獲得任意一個星期的開始時間,結束時間
function getWeekBE($day){
$lastday=date('Y-m-d',strtotime("$day Sunday"));
$firstday=date('Y-m-d',strtotime("$lastday -6 days"));
return array(strtotime($firstday), strtotime($lastday)+24*3600-1);
}


//獲得任意一個月的開始時間,結束時間
function getMonthBE($day){
$firstday = date('Y-m-01',strtotime($day));
$lastday = date('Y-m-d',strtotime("$firstday +1 month -1 day"));
return array(strtotime($firstday), strtotime($lastday)+24*3600-1);
}


print_r(getDayBE('2016-10-10'));.

print_r(getWeekBE('2016-10-20'));

print_r(getMonthBE('2012-05-2'));