PHP 获取时间段内每天的开始结束时间

时间段内每天的开始结束时间

$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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值