Rumah > Artikel > pembangunan bahagian belakang > PHP获取指定月份的第一天开始和最后一天结束的时间戳函数,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