Heim  >  Artikel  >  Backend-Entwicklung  >  PHP获取指定月份的第一天开始和最后一天结束的时间戳函数

PHP获取指定月份的第一天开始和最后一天结束的时间戳函数

WBOY
WBOYOriginal
2016-07-23 08:54:551101Durchsuche
  1. /**
  2. * 获取指定月份的第一天开始和最后一天结束的时间戳
  3. *
  4. * @param int $y 年份 $m 月份
  5. * @return array(本月开始时间,本月结束时间)
  6. */
  7. function mFristAndLast($y="",$m=""){
  8. if($y=="") $y=date("Y");
  9. if($m=="") $m=date("m");
  10. $m=sprintf("%02d",intval($m));
  11. $y=str_pad(intval($y),4,"0",STR_PAD_RIGHT);
  12. $m>12||$m $firstday=strtotime($y.$m."01000000");
  13. $firstdaystr=date("Y-m-01",$firstday);
  14. $lastday = strtotime(date('Y-m-d 23:59:59', strtotime("$firstdaystr +1 month -1 day")));
  15. return array("firstday"=>$firstday,"lastday"=>$lastday);
  16. }
复制代码

PHP


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