时间段内每天的开始结束时间
$starttime = strtotime('2019-10-01');//开始时间
$endtime = strtotime('2019-10-05');//结束时间
while ($endtime >= $starttime) {
$temp_time = $starttime;
echo date('Y-m-d H:i:s', $temp_time) . ' - ' . date('Y-m-d H:i:s', $temp_time + 86399) ."\n";
$temp_time = strtotime('+1 day', $starttime);
$starttime = $temp_time;
}
输出:
2019-10-01 00:00:00 - 2019-10-01 23:59:59
2019-10-02 00:00:00 - 2019-10-02 23:59:59
2019-10-03 00:00:00 - 2019-10-03 23:59:59
2019-10-04 00:00:00 - 2019-10-04 23:59:59
2019-10-05 00:00:00 - 2019-10-05 23:59:59
获取时间段内的每天时间
$stime = strtotime('2019-10-01');
$etime = strtotime('2019-10-5');
$datearr = [];
while ($stime <= $etime) {
$datearr[] = date('Y-m-d', $stime);//得到dataarr的日期数组。
$stime = $stime + 86400;
}
print_r($datearr);
时间段内每月的开始结束时间
$strat_month = strtotime('2019-01-01');
$end_month = strtotime('2019-05-01');
while ($end_month >= $strat_month) {
echo date('Y-m-d H:i:s', $strat_month).' - '.date('Y-m-d H:i:s', (strtotime('+1 Month', $strat_month)-1))."\n";
$strat_month = strtotime('+1 Month', $strat_month);
}
输出:
2019-01-01 00:00:00 - 2019-01-31 23:59:59
2019-02-01 00:00:00 - 2019-02-28 23:59:59
2019-03-01 00:00:00 - 2019-03-31 23:59:59
2019-04-01 00:00:00 - 2019-04-30 23:59:59
2019-05-01 00:00:00 - 2019-05-31 23:59:59