// Variable Declaration var $NOW; var $curMonth; var $curYear; var $curtxtMonth; var $curDate; var $curDay; var $thisMonth; var $TempMonth; var $totalDays;
function calendar(){ //Purpose : Constructor of the class and responsible for Variable Initialization $this->curtxtMonth=array("","January","February","March","April","May","June","July","August","September","October","November","December"); $this->curDay=1; } function AssignDate($Month,$Year){ //Purpose : Assign Values to Global variable $NOW=getdate(); // get the Current server date. if($Month > 12 || $Month < 1) { $Month = 0; $Year=0;} if($Month == 0){ $this->curMonth= $NOW[mon]; } else{ $this->curMonth= $Month; } if($Year == 0){ $this->curYear = $NOW[year]; } else{ $this->curYear = $Year; } $this->thisMonth=$this->curMonth; $this->TempMonth=$NOW[month]; }
http://www.365ju.com/jw_php/calendar.php?y=&&m=9
http://www.365ju.com/jw_php/calendar.php?y=&&m=10
不同的,月份生成的格式都是不同的。菜鸟请看清了再说。
// Variable Declaration
var $NOW;
var $curMonth;
var $curYear;
var $curtxtMonth;
var $curDate;
var $curDay;
var $thisMonth;
var $TempMonth;
var $totalDays;
function calendar(){
//Purpose : Constructor of the class and responsible for Variable Initialization
$this->curtxtMonth=array("","January","February","March","April","May","June","July","August","September","October","November","December");
$this->curDay=1;
} function AssignDate($Month,$Year){
//Purpose : Assign Values to Global variable
$NOW=getdate(); // get the Current server date.
if($Month > 12 || $Month < 1) { $Month = 0; $Year=0;}
if($Month == 0){
$this->curMonth= $NOW[mon];
}
else{
$this->curMonth= $Month;
}
if($Year == 0){
$this->curYear = $NOW[year];
}
else{
$this->curYear = $Year;
}
$this->thisMonth=$this->curMonth;
$this->TempMonth=$NOW[month];
}
function GenerateCalendar(){
//Purpose: Generate the Calendar based on the available Values
$cellCount=0;
$TableCC=0;
echo "<table align=\"center\" cellpadding=\"1\" cellspacing=\"1\" border=\"0\">";
echo "<tr bgcolor=\"#99CCFF\">";
echo "<th colspan=\"7\">".$this->curtxtMonth[$this->curMonth]." - ".$this->curYear."</th>";
echo "</tr>";
echo "<tr bgcolor=\"#99CCFF\">";
echo "<th><strong>Sun </strong></th><th><strong>Mon </strong></th><th><strong>Tue </strong></th>";
echo "<th><strong>Wed </strong></th><th><strong>Thu </strong></th><th><strong>Fri </strong></th>";
echo "<th><strong>Sat </strong></th>";
echo "</tr>";
// Dynamic Calendar Generation Starts Here//
if($TableCC == 0 ) {
echo " <tr align=\"center\" bgcolor=\"#FFFFFF\">";
}
echo " <td bgcolor=\"#FFFFFF\">";
while($this->curMonth==$this->thisMonth)
{
$this->thisMonth=date("m",mktime(23,59,59,$this->curMonth,$this->curDay,$this->curYear));
$this->totalDays=date("d",mktime(23,59,59,$this->curMonth,$this->curDay-1,$this->curYear));
$this->curDay++;
} $firstDayOfMonth = date("w",mktime(0,0,0,$this->curMonth,1,$this->curYear));
if ($firstDayOfMonth > 0) { echo "<tr>"; }
for($cellCount=0;$cellCount<=$firstDayOfMonth-1;$cellCount++)
{
echo "<td> </td>\r";
}
for ($this->curDay=1;$this->curDay<=$this->totalDays;$this->curDay++)
{
if ($cellCount == 0) { echo "<tr>\r"; }
if (($this->curDay == $this->curDate) && ($this->TempMonth == $this->curtxtMonth[$this->curMonth])){
echo "<td id=\"$this->curMonth-$this->curDay\">";
echo $this->curDay."</td>";
}
else{
echo "<td id=\"$this->curMonth-$this->curDay\">";
echo $this->curDay."</td>";
}
$cellCount++;
if ($cellCount == 7) { echo "</tr>\r"; $cellCount=0;}
} // $this->curDay Loop
if ($cellCount > 0 && $cellCount < 7)
{
for ($i=$cellCount; $i<7; $i++)
{
echo "<td>\r";
}
echo "</tr>\r";
}
$TableCC++;
if ($TableCC == 3) { echo "</tr>\r"; $TableCC = 0; }
echo "</td>";
echo "</table>";
}// GenerateCalendar() Function Ends here.
}
?> ===================================
<?php
require_once("calendar.class.php"); $cal = new calendar();
$Month = 12;
$Year = 1988; // Calendar For Assigned Date
$cal->AssignDate($Month,$Year); // Required Parameter is Month and Year, respectively
$cal->GenerateCalendar(); ?>
http://www.365ju.com/jw_php/calendar.php?y=&&m=9
http://www.365ju.com/jw_php/calendar.php?y=&&m=10
不同的,月份生成的格式都是不同的。菜鸟请看清了再说。
======================================================我认输,我是菜鸟, 你是天才。
// 显示某天所在月份的日历
/*
* param: $time timestamp of desired date and time
*/
function calendar($time)
{
$start=mktime(0, 0, 0, date('m', $time), 1, date('Y', $time));
$start=$start-date('w', $start)*86400; // extent to start of week
$end=mktime(0, 0, 0, date('m', $time)+1, 1, date('Y', $time));
$end=$end+(7-date('w', $end))*86400; // extent to end of week
//$sWeekday=array('日','一','二','三','四','五','六');
$sWeekday=array('S','M','T','W','T','F','S');
$title=date('M Y', $time);
$prev=mktime(0, 0, 0, date('m', $time)-1, 1, date('Y', $time));
$next=mktime(0, 0, 0, date('m', $time)+1, 1, date('Y', $time));
$url=$_SERVER['PHP_SELF'].'?time=';
$str = '';
$str .= <<<END
<table class="calendar" cellspacing="1">
<tr class="title">
<th colspan="2"><a href="{$url}{$prev}"><<</a></th>
<th colspan="3">{$title}</td>
<th colspan="2"><a href="{$url}{$next}">>></a></th>
</tr>
<tr class="head">
<th>{$sWeekday[0]}</td>
<th>{$sWeekday[1]}</td>
<th>{$sWeekday[2]}</td>
<th>{$sWeekday[3]}</td>
<th>{$sWeekday[4]}</td>
<th>{$sWeekday[5]}</td>
<th>{$sWeekday[6]}</td>
</tr>
<tr>
END;
for($stamp=$start;$stamp<$end;$stamp+=86400) // loop through each day, which is 86400 seconds
{
$weekday=date('w', $stamp);
if(date('m', $stamp)!=date('m', $time)) $style='exmonth';
else if(date('Y-m-d', $stamp)==date('Y-m-d')) $style='today';
else if(date('w', $stamp)==0 || date('w', $stamp)==6) $style='weekend';
else $style='weekday';
$str.= "\t\t".'<td class="'.$style.'"><a href="'.$url.$stamp.'">'.sprintf('%d',date('d', $stamp)).'</a></td>'."\n";
if(date('w', $stamp)==6) $str.="\t".'</tr>'."\n";
}
$str .= '</table>';
return $str;
}
?>
模板是用PHPLIB吧???把替换那段也贴一贴啊
拜托,
http://www.365ju.com/jw_php/calendar.php?y=&&m=9
http://www.365ju.com/jw_php/calendar.php?y=&&m=10
不同的,月份生成的格式都是不同的。菜鸟请看清了再说。
===================================================
从LZ 最后一句话中 听的不是很爽。有 bs 人的意思。
如果我知道,我都不会回答。虽然我是 菜鸟。
而且这个问题不是很难吧