Author: bjbs_270
A period of time to do one months report statistics with the title function, combined with others with mktime () function I wrote a But then always wrong, depressed pole. Take a little time on weekends to write one, and hopefully it will be useful to some villagers.
PHP Code:--------------------------------------------------------------------------------
/*
* Author: Heart lamp
* Function: Implements a function that pushes n months from a specified time
* Month ($YMD, $len) $ymd time, $len launch months
* $ymd =2005-01-01;
*/
Function month ($ymd =, $len =12) {
$month = Array ();
$lang = $lang. " ";
if ($YMD) {//Determine if the time format is correct
if (!ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $ymd)) {
echo "";
Exit
}
}
if ($len) {
if (!ereg ("[0-9]+", $len)) {
echo $lang. "";
Exit
}
}
for ($i =0; $i < $len; $i + +) {
if ($i ==0) {
$mktime = $ymd? Strtotime ($YMD): Time ();
}
$month [] = Date ("Y-m", $mktime);//You can design the format you want according to your needs.
$day = Date ("T", $mktime);
if ($i ==0)
$reday = Date ("D", $mktime);
Else
$reday = $day;
$t 1 = $mktime;
$mktime =date ("y-m-d", Mktime (Date ("H", $t 1), date ("I", $t 1), date ("s", $t 1), date ("M", $t 1), date ("D", $t 1)-$reday, date ( "Y", $t 1)));
$mktime =strtotime ($mktime);
}
return $month;
}
$month = month ();
foreach ($month as $key = = $v) {
echo $v. "
";
}
?>
--------------------------------------------------------------------------------
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
http://www.bkjia.com/PHPjc/532010.html www.bkjia.com true http://www.bkjia.com/PHPjc/532010.html techarticle Author: bjbs_270 A period of time to do one months report statistics with the title function, combined with others with mktime () function I wrote a But then always wrong, depressed pole. Take a weekend off ...