Introduction: In the time processing, for the front/background humanized display of the current month maximum number of days , this is the site must deal with an aspect. But usually this piece is packaged directly by a third-party class library, where we make a simple mark.
Today, we provide you with a function to get the first and last day of a given month !
Please read the tutorial directly!
function function
The function is very simple, and the following is the way to put it
Syntax:array (firstday=>, lastday=>) = Firstandlastday(year, month)
Parameter resolution:
$y-year
$m-month
return Result:
Array (month start time timestamp, month end time timestamp)
<?PHP/** * Gets the timestamp of the beginning of the first day of the specified month and the end of the last day * * @param int $y year $m month * @return Array (month start time, end of month)*/functionFristandlastday ($y= "",$m= "") { if($y== "")$y=Date("Y"); if($m== "")$m=Date("M"); $m=sprintf("%02d",intval($m)); $y=Str_pad(intval($y), 4, "0",str_pad_right); $m>12 | |$m<1?$m=1:$m=$m; $firstday=Strtotime($y.$m. "01000000"); $firstdaystr=Date("y-m-01",$firstday); $lastday=Strtotime(Date(' Y-m-d 23:59:59 ',Strtotime("$firstdaystr+1 month-1 Day "))); return Array( "FirstDay" =$firstday, "lastday" =$lastday );}?>
Note: This example does not format the returned result day, whether add 0 or no 0, the developer can re-update the function to meet their own requirements. :)
Example 1:
<?PHP//Query Year$year= ' 2015 ';//Query Month$month= ' 10 ';//get the first day and the last day$data= Fristandlastday ($year,$month);//Output ResultsEcho("First day Timestamp: {$data[' FirstDay ']} <br/> ");Echo("Last day Timestamp: {$data[' Lastday ']} <br/> ");
Conclusion
Just do a simple mark to sign PHP to learn the new category-< date , and open it up.
Not finished, waiting to be updated ...
This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )
Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4822607.html
[PHP Learning Tutorial-date/Time]001. First day of month & last day