Year php obtain a specified date, month, number of days of the current month, day of the week

Ado, directly on the code:

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

   }

Published 43 original articles · won praise 60 · views 6744

Guess you like

Origin blog.csdn.net/yuhang01/article/details/103455111