日期的获取
// 下拉菜单获取今日,昨日,上周 public function payOnlineDateChange($date = "") { $dt = Carbon::now(); //本周 //当前日期 $sdefaultDate = date("Y-m-d"); //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期 $first=1; //获取当前周的第几天 周日是 0 周一到周六是 1 - 6 $w=date('w',strtotime($sdefaultDate)); //获取本周开始日期,如果$w是0,则表示周日,减去 6 天 $week_start = date('Y-m-d',strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days')); //本周结束日期 $week_end = date('Y-m-d',strtotime("$week_start +6 days")); $m = date('Y-m-d', mktime(0,0,0,date('m')-1,1,date('Y'))); //上个月的开始日期 $t = date('t',strtotime($m)); //上个月共多少天 if($date == 'today'){ return response()->json([ 'start'=> $sdefaultDate, 'end' => $sdefaultDate ]); } if($date == 'yesterday'){ return response()->json([ 'start'=> $dt->yesterday()->toDateString(), 'end' => $dt->yesterday()->toDateString() ]); } if($date == 'week'){ return response()->json([ 'start'=> $week_start, 'end' => $week_end ]); } if($date == 'month'){ return response()->json([ 'start'=> date('Y-m-d',mktime(0,0,0,date('m'),1,date('Y'))), 'end' => date('Y-m-d',mktime(23,59,59,date('m'),date('t'),date('Y'))) ]); } if($date == 'month_ym'){ $startTine = date('Y-m-d',mktime(0,0,0,date('m'),1,date('Y'))); $endTime = date('Y-m-d',strtotime('-1 day')); if($endTime < $startTine){ $endTime = $startTine; } return response()->json([ 'start'=> $startTine, 'end' => $endTime ]); } if($date == 'lastMonth'){ return response()->json([ 'start'=> date('Y-m-d', mktime(0,0,0,date('m')-1,1,date('Y'))), 'end' => date('Y-m-d', mktime(0,0,0,date('m')-1,$t,date('Y'))) ]); } if($date == 'lastlastMonth'){ return response()->json([ 'start'=> date('Y-m-d', mktime(0,0,0,date('m')-2,1,date('Y'))), 'end' => date('Y-m-d', mktime(0,0,0,date('m')-2,$t,date('Y'))) ]); } if($date == 'lastthisMonth'){ return response()->json([ 'start'=> date('Y-m-d', mktime(0,0,0,date('m')-2,1,date('Y'))), 'end' => date('Y-m-d', mktime(0,0,0,date('m')-1,$t,date('Y'))) ]); } }