Introduction: This is a detailed page for pushing down functions for N months from a specified time. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 326942 'rolling = 'no'>
Author: bjbs_270
Some time ago, I made a monthly report statistics and used the topic-like function. I wrote one using the mktime () function, but it was always wrong and depressing. I would like to take some time over the weekend to write one for some villagers.
PHPCode:--------------------------------------------------------------------------------
<?
/*
* Author: Heart Lamp
* Function: implements the function of pushing down n months from the specified time.
* Month ($ ymd, $ Len) $ ymd time, $ Len released several months
* $ Ymd = '2017-01-01 ';
*/
Function month ($ ymd = ', $ Len = '12 '){
$ Month = array ();
$ Lang = $ Lang. "<meta http-equiv = \" Content-Type \ "content = \" text/html; charset = gb2312 \ "> ";
If ($ ymd) {// determine whether the time format is correct
If (! Ereg ("([0-9] {4})-([0-9] {1, 2})-([0-9] {1, 2 })", $ ymd )){
Echo "<SCRIPT> alert ('date format in function parameters'); history. Back () </SCRIPT> ";
Exit;
}
}
If ($ Len ){
If (! Ereg ("[0-9] +", $ Len )){
Echo $ Lang. "<SCRIPT> alert ('invalid time length in the function '); history. Back () </SCRIPT> ";
Exit;
}
}
For ($ I = 0; $ I <$ Len; $ I ++ ){
If ($ I = 0 ){
$ Mktime = $ ymd? Strtotime ($ ymd): Time ();
}
$ Month [] = date ("Y-M", $ mktime); // you can design your desired format as needed.
$ Day = date ("T", $ mktime );
If ($ I = 0)
$ Reday = date ("D", $ mktime );
Else
$ Reday = $ Day;
$ T1 = $ mktime;
$ Mktime = date ("Y-m-d", mktime (date ("H", $ T1), date ("I", $ T1 ), date ("S", $ T1), date ("M", $ T1), date ("D", $ T1)-$ reday, date ("Y ", $ T1 )));
$ Mktime = strtotime ($ mktime );
}
Return $ month;
}
$ Month = month ();
Foreach ($ month as $ key => $ v ){
Echo $ v. "<br> ";
}
?>
--------------------------------------------------------------------------------
The effect is as follows:
2005-01
2004-12
2004-11
2004-10
2004-09
2004-08
2004-07
2004-06
2004-05
2004-04
2004-03
2004-02
More articles about how to push down functions for N months at a specified time
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/326942.html pageno: 13.