Heim  >  Artikel  >  php教程  >  php获取指定月的某一天的日期

php获取指定月的某一天的日期

WBOY
WBOYOriginal
2016-06-07 11:45:041386Durchsuche

php获取指定月的某一天的日期
   /**<br>       * 获取指定月的第几天的日期<br>       * @$year 年,$month月,$day天,$format显示时间的格式,$last是否该月最后一天<br>       * @return $str<br>       */<br> function getMonthDay($year,$month,$day,$format='Y-m-d',$last=0){<br>         if($last){<br>             $time=new DateTime($day);        <br>             $d=strtotime($time->format("Y-m-d"));<br>             $d=date("t",$d);<br>             $time->setDate($year,$month,$d);<br>         }else{<br>             $time=new DateTime();<br>             $time->setDate($year,$month,$day);<br>         }<br>         return $time->format($format);<br>     }如要获取2013年3月第一天,getMonthDay(2013,3,1)返回:2013-03-01
如要获取2013年最后一天,getMonthDay(2013,2,'',1)返回2013-02-28

AD:真正免费,域名+虚机+企业邮箱=0元

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn