php 獲取指定日期的年份,月份,當前月的天數,星期幾

廢話不多說,直接上代碼:

  //將日期格式 如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

   }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章