Get all days and date for a given month

后端 未结 9 1516
天涯浪人
天涯浪人 2021-02-10 08:17

Would like to retrieve all days and date for a given month. Have this currently which shows all the days for the current month, but how do I parse in a specified month instead?<

9条回答
  •  梦如初夏
    2021-02-10 08:45

    for object oriented users,

    function getDaysInYearMonth (int $year, int $month, string $format){
      $date = DateTime::createFromFormat("Y-n", "$year-$month");
    
        $datesArray = array();
        for($i=1; $i<=$date->format("t"); $i++){
            $datesArray[] = DateTime::createFromFormat("Y-n-d", "$year-$month-$i")->format($format);
        }
    
     return $datesArray;
    }
    

提交回复
热议问题