/* 按照格式获取时间的周期 */
function getPeriod($begin_date, $end_date, $period)
{
$begin_time_stamp = strtotime($begin_date);
$end_time_stamp = strtotime($end_date);
$period_arr = array();
if ($period == 'daily')
{
while ($begin_time_stamp <= $end_time_stamp)
{
$arr['begin'] = date('Y-m-d H:i:s', $begin_time_stamp);
$current_end_stamp = strtotime(date('Y-m-d 23:59:59', $begin_time_stamp));
if ($current_end_stamp > $end_time_stamp)
{
$arr['end'] = date('Y-m-d H:i:s', $end_time_stamp);
}
else
{
$arr['end'] = date('Y-m-d H:i:s', $current_end_stamp);
}
$period_arr[] = $arr;
$begin_time_stamp = $current_end_stamp + 1;
}
}
if ($period == 'weekly')
{
while ($begin_time_stamp <= $end_time_stamp)
{
$arr['begin'] = date('Y-m-d H:i:s', $begin_time_stamp);
$current_end_stamp = strtotime(date('Y-m-d 23:59:59', strtotime(date('Y-m-d H:i:s', $begin_time_stamp) . '+ ' . (7 - date('N', $begin_time_stamp)) . ' day')));
if ($current_end_stamp > $end_time_stamp)
{
$arr['end'] = date('Y-m-d H:i:s', $end_time_stamp);
}
else
{
$arr['end'] = date('Y-m-d H:i:s', $current_end_stamp);
}
$period_arr[] = $arr;
$begin_time_stamp = $current_end_stamp + 1;
}
}
if ($period == 'monthly')
{
while ($begin_time_stamp <= $end_time_stamp)
{
$arr['begin'] = date('Y-m-d H:i:s', $begin_time_stamp);
$current_end_stamp = strtotime(date('Y-m-t 23:59:59', $begin_time_stamp));
if ($current_end_stamp > $end_time_stamp)
{
$arr['end'] = date('Y-m-d H:i:s', $end_time_stamp);
}
else
{
$arr['end'] = date('Y-m-d H:i:s', $current_end_stamp);
}
$period_arr[] = $arr;
$begin_time_stamp = $current_end_stamp + 1;
}
}
return $period_arr;
}
function getPeriod($begin_date, $end_date, $period)
{
$begin_time_stamp = strtotime($begin_date);
$end_time_stamp = strtotime($end_date);
$period_arr = array();
if ($period == 'daily')
{
while ($begin_time_stamp <= $end_time_stamp)
{
$arr['begin'] = date('Y-m-d H:i:s', $begin_time_stamp);
$current_end_stamp = strtotime(date('Y-m-d 23:59:59', $begin_time_stamp));
if ($current_end_stamp > $end_time_stamp)
{
$arr['end'] = date('Y-m-d H:i:s', $end_time_stamp);
}
else
{
$arr['end'] = date('Y-m-d H:i:s', $current_end_stamp);
}
$period_arr[] = $arr;
$begin_time_stamp = $current_end_stamp + 1;
}
}
if ($period == 'weekly')
{
while ($begin_time_stamp <= $end_time_stamp)
{
$arr['begin'] = date('Y-m-d H:i:s', $begin_time_stamp);
$current_end_stamp = strtotime(date('Y-m-d 23:59:59', strtotime(date('Y-m-d H:i:s', $begin_time_stamp) . '+ ' . (7 - date('N', $begin_time_stamp)) . ' day')));
if ($current_end_stamp > $end_time_stamp)
{
$arr['end'] = date('Y-m-d H:i:s', $end_time_stamp);
}
else
{
$arr['end'] = date('Y-m-d H:i:s', $current_end_stamp);
}
$period_arr[] = $arr;
$begin_time_stamp = $current_end_stamp + 1;
}
}
if ($period == 'monthly')
{
while ($begin_time_stamp <= $end_time_stamp)
{
$arr['begin'] = date('Y-m-d H:i:s', $begin_time_stamp);
$current_end_stamp = strtotime(date('Y-m-t 23:59:59', $begin_time_stamp));
if ($current_end_stamp > $end_time_stamp)
{
$arr['end'] = date('Y-m-d H:i:s', $end_time_stamp);
}
else
{
$arr['end'] = date('Y-m-d H:i:s', $current_end_stamp);
}
$period_arr[] = $arr;
$begin_time_stamp = $current_end_stamp + 1;
}
}
return $period_arr;
}
来源:原创
发布时间:2020-08-14 21:40:28