Home > Backend Development > PHP Tutorial > PHP gets the timestamp function that starts on the first day and ends on the last day of a specified month, php last day_PHP tutorial

PHP gets the timestamp function that starts on the first day and ends on the last day of a specified month, php last day_PHP tutorial

WBOY
Release: 2016-07-12 08:51:34
Original
909 people have browsed it

PHP function to get the timestamp of the first day of the specified month and the end of the last day, php last day

A php function to get the first and last day of the month, Functions collected online, but this function feels a bit cumbersome to implement. There is also a similar function in the recommended reading in this article, you can also take a look.

<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>
Copy after login

Recommended: http://www.cnblogs.com/roucheng/p/phpexcel.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1130141.htmlTechArticlePHP gets the timestamp function that starts on the first day of the specified month and ends on the last day. One php gets the last day of the month. The functions of the first and last day of the month are functions collected online, but this...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template