获取前五年的全部年份
$date = date('Y'); for ($i=0;$i<=5;$i++) { $years[$i] = $date-$i; }
获取一年全部月份
$StartMonth = date('Y-m',strtotime('-1 year')); //开始日期 $EndMonth = date('Y-m'); //结束日期 $ToStartMonth = strtotime( $StartMonth ); //转换一下 $ToEndMonth = strtotime( $EndMonth ); //一样转换一下 $i = false; //开始标示 while( $ToStartMonth < $ToEndMonth ) { $NewMonth = !$i ? date('Y-m', strtotime('+0 Month', $ToStartMonth)) : date('Y-m', strtotime('+1 Month', $ToStartMonth)); $ToStartMonth = strtotime( $NewMonth ); $i = true; $re[] = $NewMonth; }
获取一月全部天数
$begin = date('Y-m-d',strtotime('-1 month')); $end = date('Y-m-d'); $begintime = strtotime($begin); $endtime = strtotime($end); for ($start = $begintime; $start <= $endtime; $start += 24 * 3600) { $re[] = date("Y-m-d", $start); }