/**
* 获取指定时间的本月起止时间
* @param $time int
* @return mixed 11
*/
function currentMonth($time)
{
$info['start'] = strtotime(date( 'Y-m-1 00:00:00', $time ));
$mdays = date( 't', $time );
$info['end'] = strtotime(date( 'Y-m-' . $mdays . ' 23:59:59', $time ));
return $info;
}
/**
* 获取指定时间的上个月起止时间
* @param $time int
* @return mixed 11
*/
function lastMonth($time)
{
$datetime = date('Ymd',$time);
$info['start'] = strtotime(date("Y-m-1 00:00:00",strtotime("last months",strtotime($datetime))));
$mdays = date( 't', $time );
$info['end'] = strtotime(date( 'Y-m-' . $mdays . ' 23:59:59', $info['start']));
return $info;
}
/**
* 获取指定时间下个月的起止时间(Y-m-d)
* @param $time /int
* @return array
*/
function nextMonth($time){
$arr=getdate($time);
if($arr['mon'] == 12){
$year=$arr['year'] +1;
$month=$arr['mon'] -11;
$firstday=$year.'-0'.$month.'-01';
$lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
}else{
$firstday=date('Y-m-01',strtotime(date('Y',$time).'-'.(date('m',$time)+1).'-01'));
$lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
}
$info['start'] = $firstday;
$info['end'] = $lastday;
return $info;
}
/**
* 获取指定时间上一年对应月份的起止时间
* @param $time
* @return mixed
*/
function lastYearMonth($time)
{
$info['start'] = strtotime(date( 'Y-m-01 00:00:00', strtotime("-1 years",$time) ));
$mdays = date( 't', $time );
$info['end'] = strtotime(date( 'Y-m-' . $mdays . ' 23:59:59', strtotime("-1 years",$time) ));
return $info;
}
/**
* 获取指定时间的当年起止时间
* @param $time int
* @return mixed 11
*/
function currentYear($time)
{
$info['start'] = strtotime(date( 'Y-01-01 00:00:00', $time ));
$info['end'] = strtotime(date( 'Y-12-31 23:59:59', $time ));
return $info;
}
/**
* 获取指定时间的上一年起止时间
* @param $time int
* @return mixed 11
*/
function lastYear($time)
{
$info['start'] = strtotime(date( 'Y-01-01 00:00:00', strtotime("-1 years",$time) ));
$info['end'] = strtotime(date( 'Y-12-31 23:59:59', strtotime("-1 years",$time) ));
return $info;
}
/**
* 输入起止时间查询所有月份("Y-m"格式)
* @param $params
* @param int $k
* @return array
*/
function allMonth($params,$k=0)
{
//先算月份,再算开始时间的月份开始/结束时间,再算结束时间的月份开始结束时间
$mouth = array();
$start = (date( 'Y-m', $params['startTime'] ));
$end = (date( 'Y-m', $params['endTime']));
if($start <= $end){
$mouth[$k] = $end;
$params['endTime'] = strtotime(date( 'Y-m', strtotime("last months",$params['endTime'])));
$mouth = array_merge($mouth,allMonth($params,$k+1));
}
return $mouth;
}
php 获取时间
最新推荐文章于 2022-04-06 18:48:49 发布