廢話不多說,直接上代碼:
//将日期格式 如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
}