首页  >  文章  >  php教程  >  php获取指定月的某一天的日期

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

WBOY
WBOY原创
2016-06-07 11:45:041384浏览

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元

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn