$k=0;1;2;3;4;5...
/***
* 日期方法
*/
public function djday($k){
if($k==0){ //当天
$arr['begin_time'] =mktime(0,0,0,date('m'),date('d'),date('y'));
$arr['end_time'] =mktime(0,0,0,date('m'),date('d')+1,date('y'))-1;
}else{ //获取昨天的起始时间戳或者 弟n天 开始时间与结束时间
$arr['begin_time'] = mktime(0,0,0,date('m'),date('d')-$k,date('y'));
$arr['end_time'] = mktime(23,59,59,date('m'),date('d')-$k,date('y'));
}
return $arr;
}
return 今天,昨天,前天....开始时间和结束时间
######################################################################################
function getNextMonthDays($date,$k=0){
$date = $date.'01';
$m = date('m',strtotime($date));
$y = date('Y',strtotime($date));
//$endThismonth=mktime(23,59,59,$m-$k,date('t'),$y);
if($y=="") $y=date("Y");
if($m=="") $m=date("m");
$m=sprintf("%02d",intval($m));
$y=str_pad(intval($y),4,"0",STR_PAD_RIGHT);
$m>12||$m<1?$m=1:$m=$m;
$stratThismonth = mktime(0,0,0,$m-$k,1,$y);
$firstdaystr = $firstdaystr=date("Y-m-01",$stratThismonth);
$endThismonth = strtotime(date('Y-m-d 23:59:59', strtotime("$firstdaystr +1 month-1 day")));
//$endThismonth=mktime(23,59,59,$m-$k,date('t'),$y);
$arr['start_month_time'] = $stratThismonth;
$arr['end_month_time'] = $endThismonth;
$arr['curent_date'] = date("Y-m",time());
return $arr;
}
返回:当月,上月,上上月.....开始时间结束时间
常用时间处理
最新推荐文章于 2025-04-03 10:06:25 发布
本文详细探讨了PHP中处理时间的各种方法,包括日期格式化、时间戳转换、时间间隔计算等核心概念,旨在帮助开发者更高效地管理和操作时间数据。
4万+

被折叠的 条评论
为什么被折叠?



