如果喜欢我网站右边日历,可以复制我编写的代码,代码是用php编写的,如果想要改成别的语言,那也可以参考参考,要是大家发现有什么不足和漏洞,请记得及时提醒和联系我喔。记住转载的时候挂上我的链接,我将非常感谢您!
<?php
function printCalendar(){
?>
<table width="" border="0" cellspacing="1" bgcolor="#FFFFFF">
<caption><?php date_default_timezone_set('PRC'); echo date('F Y'); ?></caption>
<tr>
<th height="20" width="35" align="center" style="color:#F00" bgcolor="#ECFFEC">Sun</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Mon</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Tue</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Wed</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Thu</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Fri</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Sat</th>
</tr>
<?php
$putTD = true;
$putTR = true;
for($i = 1; $i <= date('t'); $i++){
if($putTR == true){
?>
<tr>
<?php
$putTR = false;
}
if($putTD == true){
if(checkWeek(date('Y-n-1')) != 0){
?>
<td height="20" colspan="<?php echo checkWeek(date('Y-n-1')); ?>" bgcolor="#ECFFEC"></td>
<?php
}
$putTD = false;
}
if($i == date('j')){
?>
<td width="30" height="20" align="center" style="background:#BFB;color:#009;"><?php echo $i; ?></td>
<?php
} else {
?>
<td width="30" height="20" align="center" bgcolor="#ECFFEC"><?php echo $i; ?></td>
<?php
}
if(checkWeek(date("Y-n-$i")) == 6){
?>
</tr>
<?php
$putTR = true;
}
if($i == date('t') && checkWeek(date("Y-n-$i")) != 6){
if((6 - checkWeek(date("Y-n-$i"))) != 0){
?>
<td height="20" colspan="<?php echo (6 - checkWeek(date("Y-n-$i"))); ?>" bgcolor="#FFFFFF"></td>
<?php
}
?>
</tr>
<?php
}
}
?>
</table>
<?php
}
function checkWeek($date){ //判断星期几
//$date = "2008-06-25";
$datearr = explode("-",$date);
$year = $datearr[0];
$month = sprintf('%02d', $datearr[1]);
$day = sprintf('%02d',$datearr[2]);
$hour = $minute = $second = 0;
$dayofweek = getdate(mktime($hour, $minute, $second, $month, $day, $year));
$weekday = $dayofweek['weekday'];
$wday = $dayofweek['wday'];
return $wday;
}
printCalendar();
?>
function printCalendar(){
?>
<table width="" border="0" cellspacing="1" bgcolor="#FFFFFF">
<caption><?php date_default_timezone_set('PRC'); echo date('F Y'); ?></caption>
<tr>
<th height="20" width="35" align="center" style="color:#F00" bgcolor="#ECFFEC">Sun</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Mon</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Tue</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Wed</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Thu</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Fri</th>
<th height="20" width="35" align="center" style="color:#000" bgcolor="#ECFFEC">Sat</th>
</tr>
<?php
$putTD = true;
$putTR = true;
for($i = 1; $i <= date('t'); $i++){
if($putTR == true){
?>
<tr>
<?php
$putTR = false;
}
if($putTD == true){
if(checkWeek(date('Y-n-1')) != 0){
?>
<td height="20" colspan="<?php echo checkWeek(date('Y-n-1')); ?>" bgcolor="#ECFFEC"></td>
<?php
}
$putTD = false;
}
if($i == date('j')){
?>
<td width="30" height="20" align="center" style="background:#BFB;color:#009;"><?php echo $i; ?></td>
<?php
} else {
?>
<td width="30" height="20" align="center" bgcolor="#ECFFEC"><?php echo $i; ?></td>
<?php
}
if(checkWeek(date("Y-n-$i")) == 6){
?>
</tr>
<?php
$putTR = true;
}
if($i == date('t') && checkWeek(date("Y-n-$i")) != 6){
if((6 - checkWeek(date("Y-n-$i"))) != 0){
?>
<td height="20" colspan="<?php echo (6 - checkWeek(date("Y-n-$i"))); ?>" bgcolor="#FFFFFF"></td>
<?php
}
?>
</tr>
<?php
}
}
?>
</table>
<?php
}
function checkWeek($date){ //判断星期几
//$date = "2008-06-25";
$datearr = explode("-",$date);
$year = $datearr[0];
$month = sprintf('%02d', $datearr[1]);
$day = sprintf('%02d',$datearr[2]);
$hour = $minute = $second = 0;
$dayofweek = getdate(mktime($hour, $minute, $second, $month, $day, $year));
$weekday = $dayofweek['weekday'];
$wday = $dayofweek['wday'];
return $wday;
}
printCalendar();
?>