-
-
- /*
- * php calendar function
- * edit: bbs.it-home.org
- */
- @date_default_timezone_set('RPC');
-
function show_calender(){
- $starttime=microtime();
//Processing request date
- $y= isset($_GET["y"]) ? intval($ _GET["y"]) : date("Y");
- $m= isset($_GET["m"]) ? intval($_GET["m"]) : date("m");
- if ($m<1 || $m>12)$m=date("m");
- if($y<=0)$y=date("Y");
$nm=$m+1; - if($nm>12){
- $nm=1;
- $ny=$y+1;
- }else{
- $ny=$y;
- }
//Previous month
- $pm=$m-1;
- if($pm<1){
- $pm=12;
- $py=$y-1;
- }else{
- $py=$y;
- }
//Get the name of this month
- $month = date("M",mktime(0, 0, 0, $m, 1, $y));
//Get the last day of this month
- $lastday = date("d",mktime(0, 0, 0, $nm, 0, $ny) );
//Get the day of the week when the day starts
- $index = date("w",mktime(0, 0, 0, $m, 1, $y));< /p>
//Generate calendar header
- echo "
n- | {$y} {$month} | + | n Day | One | Two | Three | Four< ;/td> | five | six | ";
//Processing calendar
- $row=0 ;
- $day=1;
- while(1){
- echo "
";
- if($row==0){
- for($i=0;$i<=6;$i++)
- if($i<$index)
- echo "
| ";
- else
- echo "
".$day++." | ";
- }else{
- for($i=0;$i<=6;$i++)
- if($day>$lastday)
- echo "
| ";
- else
- echo "
";
- }
- echo "
| ";
- $row++;
- if($day>$lastday)break;
- }
- echo "
$endtime=microtime();
- $usedtime=$endtime-$starttime;
- return $usedtime;
- }
$run_info= array();
- for($i=0;$i<10;$i++)
- $run_info[]=show_calender();
print_r($run_info);
- ?>
-
Copy code
Test results:
Array
(
[0] => 0.00038400000000005
[1] => 0.00030999999999998
[2] => 0.000296999999999999
[3] => 0.000303
[4] => 0.00030399999999997
[5] => 0.00034499999999998
[6] => 0.00032300000000002
[7] => 0.00033
[8] => 0.00032699999999997
[9] => 0.00032000000000004
)
>>>> Articles you may be interested in:
php calender calendar code (solve 2038 problem)
php calendar code (with demo effect)
php calendar code sharing simple and practical php calendar code
php calendar code Three good php calendar codes
Share an example of PHP simple calendar code
PHP simple calendar implementation code (can bind events)
|