廢話不多說,直接上代碼:
//將日期格式 如2019-09-09 轉換爲時間戳
$dirtime=strtotime($start);
$year = date('Y', $dirtime); // 當前指定日期的年份
$month = date('m', $dirtime); // 當前指定日期的月份
$monthend = date('t', $dirtime);//當前指定日期的天數
//獲取當前日期的年月天數
$nowtime = time();
$year = date('Y', $nowtime); // 當前指定日期的年份
$month = date('m', $nowtime); // 當前指定日期的月份
$monthend = date('t', $nowtime);//當前指定日期的天數
//由以上我們還可以拿到當前月份的每一天的時間
for ($x=1; $x<=$monthend; $x++) {
$start = strtotime($year."-".$month."-".$x);//獲取當年當月的所有日期
$today=strtotime(date('Y-m-d',$nowtime));//獲取今天日期
$data['zhou'] ="星期".date('N',$start);//星期幾
$end = strtotime($year."-".$month."-".$x)+60*60*24-1;//一天的結束日期 23:59
}