/**
* 返回今日开始和结束的时间戳
*
* @return array
*/
function today()
{
list($y, $m, $d) = explode('-', date('Y-m-d'));
return [
mktime(0, 0, 0, $m, $d, $y),
mktime(23, 59, 59, $m, $d, $y)
];
}
/**
* 返回昨日开始和结束的时间戳
*
* @return array
*/
function yesterday()
{
$yesterday = date('d') - 1;
return [
mktime(0, 0, 0, date('m'), $yesterday, date('Y')),
mktime(23, 59, 59, date('m'), $yesterday, date('Y'))
];
}
/**
* 返回本月开始和结束的时间戳
*
* @return array
*/
function month()
{
list($y, $m, $t) = explode('-', date('Y-m-t'));
return [
mktime(0, 0, 0, $m, 1, $y),
mktime(23, 59, 59, $m, $t, $y)
];
}
/**
* 返回上个月开始和结束的时间戳
*
* @return array
*/
function lastMonth()
{
$y = date('Y');
$m = date('m');
$begin = mktime(0, 0, 0, $m - 1, 1, $y);
$end = mktime(23, 59, 59, $m - 1, date('t', $begin), $y);
return [$begin, $end];
}
/**
* 返回本年开始和结束的时间戳
*/
function year(){
return [
mktime(0, 0, 0, 1, 1, date('Y')),
mktime(23, 59, 59, 12, 31, date('Y'))
];
}
/**
* 返回去年开始和结束的时间戳
*
* @return array
*/
function lastYear()
{
$year = date('Y') - 1;
return [
mktime(0, 0, 0, 1, 1, $year),
mktime(23, 59, 59, 12, 31, $year)
];
}
/**
* 返回本周开始和结束的时间戳
*
* @return array
*/
function week()
{
list($y, $m, $d, $w) = explode('-', date('Y-m-d-w'));
if($w == 0) $w = 7; //修正周日的问题
return [
mktime(0, 0, 0, $m, $d - $w + 1, $y), mktime(23, 59, 59, $m, $d - $w + 7, $y)
];
}
/**
* 获取某月第一天和最后一天
*
* @return array
*/
function getOneMonthTime($year,$month){
$date = $year.'-'.$month;
return [
date('Y-m-d', mktime(00, 00, 00, date('m', strtotime($date)), 01)),
date('Y-m-d', mktime(23, 59, 59, date('m', strtotime($date))+1, 00))
];
}
更多:https://www.kancloud.cn/manual/thinkphp5_1/354132