//当前日期前30天日期列表
public function getData30Days(){
$days=[];
for ($i=0; $i <=30; $i++) {
$days[$i]=date("Y-m-d",strtotime('-'.$i.'day'));
}
return $days;
}
//获取最近七天所有日期
function get_weeks($time = '', $format='Y-m-d')
{
$time = $time != '' ? $time : time();
//组合数据
$date = [];
for ($i=1; $i<=7; $i++) {
$date[$i] = date($format, strtotime('+' . $i-7 .' days', $time));
}
return $date;
}
//获取本周所有日期
function get_week($time = '', $format='Y-m-d'){
$time = $time != '' ? $time : time();
//获取当前周几
$week = date('w', $time);
$date = [];
for ($i=1; $i<=7; $i++){
$date[$i] = date($format ,strtotime( '+' . $i-$week .' days', $time));
}
return $date;
}
//本周所有日期开始和结束
function get_week($time = '', $format='Y-m-d'){
$time = $time != '' ? $time : time();
//获取当前周几
$week = date('w', $time);
$date = [];
for ($i=1; $i<=7; $i++){
$date[$i]['start_time'] = date($format ,strtotime( '+' . $i-$week .' days', $time));
$date[$i]['end_time'] = date($format ,strtotime( '+' . $i-$week+1 .' days', $time));
}
return $date;
}
//本月所有日期
function get_day_num($time = '', $format='Y-m-d'){
$time = $time != '' ? $time : time();
//获取当前周几
$week = date('d', $time);
$date = [];
for ($i=1; $i<=date('t'); $i++){
$date[$i-1] = date($format ,strtotime( '+' . $i-$week .' days', $time));
}
return $date;
}
//本月所有日期开始和结束
function get_day($time = '', $format='Y-m-d'){
$time = $time != '' ? $time : time();
//获取当前周几
$week = date('d', $time);
$date = [];
for ($i=1; $i<=date('t'); $i++){
$date[$i]['start_time'] = date($format ,strtotime( '+' . $i-$week .' days', $time));
$date[$i]['end_time'] = date($format ,strtotime( '+' . $i-$week+1 .' days', $time));
}
return $date;
}
//获取当前月份往前的12个月份开始和结束时间
public function getDateMouth(){
$currentTime = time();
$cyear = floor(date("Y",$currentTime));
$cMonth = floor(date("m",$currentTime));
$dataArray = [];
$num = 0;
for ($i=0;$i<12;$i++){
$array = [];
$nMonth = $cMonth-$i;
$cyear = $nMonth == 0 ? ($cyear-1) : $cyear;
if($nMonth == 0){
$nMonth = 12;
}
if($nMonth < 0){
$nMonth = 12;
$num++;
$nMonth = $nMonth-$num;
}
$date = $cyear.'-'.$nMonth;
$firstday = date("Y-m-01",strtotime($date));
$lastday = date("Y-m-t",strtotime($date));
$array[$date]["first"] = $firstday;
$array[$date]["last"] = $lastday;
$dataArray[] = $array;
}
$newArr=[];
for ($i = count($dataArray)-1;$i>=0;$i--) {
array_push($newArr,$dataArray[$i]);
}
//sort($dataArray);
return $newArr;
}
//本年所有月份开始和结束
function get_month(){
$year = date('Y');
$yeararr = [];
$month = [];
for ($i=1; $i <=12 ; $i++) {
$yeararr[$i] = $year.'-'.$i;
}
foreach ($yeararr as $key => $value) {
$timestamp = strtotime( $value );
$start_time = date( 'Y-m-1 00:00:00', $timestamp );
$mdays = date( 't', $timestamp );
$end_time = date( 'Y-m-' . $mdays . ' 23:59:59', $timestamp );
$month[$key]['start_time'] = $start_time;
$month[$key]['end_time'] = $end_time;
}
return $month;
}
//换成汉字
public function get_week($date){
$date_str=date('Y-m-d',strtotime($date));
$arr=explode("-", $date_str);
$year=$arr[0];
$month=sprintf('%02d',$arr[1]);
$day=sprintf('%02d',$arr[2]);
$hour = $minute = $second = 0;
$strap = mktime($hour,$minute,$second,$month,$day,$year);
$number_wk=date("w",$strap);
$weekArr=array("周日","周一","周二","周三","周四","周五","周六");
return $weekArr[$number_wk];
}
|