首頁 >php教程 >php手册 >PHP获取指定月份的第一天开始和最后一天结束的时间戳函数,php最后一天

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

WBOY
WBOY原創
2016-06-13 08:38:571221瀏覽

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

一个php获取月中第一天和最后一天的函数,网上搜集的函数,不过这个函数感觉实现的有点繁琐了.本篇文章推荐阅读里也有一篇同样的函数,大家也可以看一下.

<span>/*</span><span>*
 * 获取指定月份的第一天开始和最后一天结束的时间戳
 *
 * @param int $y 年份 $m 月份
 * @return array(本月开始时间,本月结束时间)
 </span><span>*//*</span><span> 何问起 hovertree.com </span><span>*/</span>
<span>function</span> mFristAndLast(<span>$y</span>="",<span>$m</span>=""<span>){
 </span><span>if</span>(<span>$y</span>=="") <span>$y</span>=<span>date</span>("Y"<span>);
 </span><span>if</span>(<span>$m</span>=="") <span>$m</span>=<span>date</span>("m"<span>);
 </span><span>$m</span>=<span>sprintf</span>("%02d",<span>intval</span>(<span>$m</span><span>));
 </span><span>$y</span>=<span>str_pad</span>(<span>intval</span>(<span>$y</span>),4,"0",<span>STR_PAD_RIGHT);
 
 </span><span>$m</span>>12||<span>$m</span><1?<span>$m</span>=1:<span>$m</span>=<span>$m</span><span>;
 </span><span>$firstday</span>=<span>strtotime</span>(<span>$y</span>.<span>$m</span>."01000000"<span>);
 </span><span>$firstdaystr</span>=<span>date</span>("Y-m-01",<span>$firstday</span><span>);
 </span><span>$lastday</span> = <span>strtotime</span>(<span>date</span>('Y-m-d 23:59:59', <span>strtotime</span>("<span>$firstdaystr</span> +1 month -1 day"<span>)));
 </span><span>return</span> <span>array</span>("firstday"=><span>$firstday</span>,"lastday"=><span>$lastday</span><span>);
}</span>

推荐:http://www.cnblogs.com/roucheng/p/phpexcel.html

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn