php萬年歷源碼
① 萬年歷 源碼編輯,修改
1.
var adds
if (perscal[2]>7)
adds = 1230
else
adds = 1130
var timeData = {
"China 中國": {
"BeiJing 北京":["+"+adds,"","北京、重慶、烏魯木齊"],//伊朗春斗做悉節過後修改胡埋為+1130,6個月後修改為+1230
"Iran 伊朗":["+0800","","德黑蘭"]
}
};
2.在HTML裡面加一個div,名字隨便了 跟著陰歷的一起跑,id=隨便取一個名字
然後用document.getElementById("id名").innerHTML="內容" 控空乎制
② php小白,做的日歷有源碼,求大神幫看看問題在哪裡,感激不盡
代碼邏輯就有問題
你的sql循環遍歷里截取了一次day應該是無用代碼,下面把數據存入數組中寫的鍵名 data 和前面寫的date並不一樣。你自己檢查一下有沒有問題。
另外 你的判斷日期是否特殊日期的邏輯里,是根據數組索引 $i 來判斷的,你能保證從資料庫取出的數據是按天排序每天都有的嗎?
一般做日期判斷可以把數據拉出來按日期索引 ,這樣後面日期判斷的時候根據鍵名來判斷就比較准確了。
//存入標志數組
$day_color[$row['date']]=true;
for(...){
$date=sprintf("%02d",$i);
if(!empty($day_color['2019-01-'.$date])){
...
}else{
...
}
}
③ 如何用PHP製作日歷
calendar.class.php
代碼如下:
<?php
classCalendar{
private$year;//當前的年
private$month;//當前的月
private$start_weekday;//當月的第一天對應的是周幾
private$days;//當前月一共多少天
function__construct(){
$this->year=isset($_GET["year"])?$_GET["year"]:date("Y");
$this->month=isset($_GET["month"])?$_GET["month"]:date("m");
$this->start_weekday=date("w",mktime(0,0,0,$this->month,1,$this->year));
$this->days=date("t",mktime(0,0,0,$this->month,1,$this->year));
}
functionout(){
echo'<tablealign="center">';
$this->chageDate("test.php");
$this->weeksList();
$this->daysList();
echo'</table>';
}
privatefunctionweeksList(){
$week=array('日','一','二','三','四','五','六');
echo'<tr>';
for($i=0;$i<count($week);$i++)
echo'<thclass="fontb">'.$week[$i].'</th>';
echo'</tr>';
}
privatefunctiondaysList(){
echo'<tr>';
//輸出空格(當前一月第一天前面要空出來)
for($j=0;$j<$this->start_weekday;$j++)
echo'<td></td>';
for($k=1;$k<=$this->days;$k++){
$j++;
if($k==date('d'))
echo'<tdclass="fontb">'.$k.'</td>';
else
echo'<td>'.$k.'</td>';
if($j%7==0)
echo'</tr><tr>';
}
//後面幾個空格
while($j%7!==0){
echo'<td></td>';
$j++;
}
echo'</tr>';
}
privatefunctionprevYear($year,$month){
$year=$year-1;
if($year<1970)
$year=1970;
return"year={$year}&month={$month}";
}
privatefunctionprevMonth($year,$month){
if($month==1){
$year=$year-1;
if($year<1970)
$year=1970;
$month=12;
}else{
$month--;
}
return"year={$year}&month={$month}";
}
privatefunctionnextYear($year,$month){
$year=$year+1;
if($year>2038)
$year=2038;
return"year={$year}&month={$month}";
}
privatefunctionnextMonth($year,$month){
if($month==12){
$year++;
if($year>2100)
$year=2100;
$month=1;
}else{
$month++;
}
return"year={$year}&month={$month}";
}
privatefunctionchageDate($url=""){
echo'<tr>';
echo'<td><ahref="?'.$this->prevYear($this->year,$this->month).'">'.'<<'.'</a></td>';
echo'<td><ahref="?'.$this->prevMonth($this->year,$this->month).'">'.'<'.'</a></td>';
echo'<tdcolspan="3">';
echo'<form>';
echo'<selectname="year"onchange="window.location=''.$url.'?year='+this.options[selectedIndex].value+'&month='.$this->month.''">';
for($sy=1970;$sy<=2100;$sy++){
$selected=($sy==$this->year)?"selected":"";
echo'<option'.$selected.'value="'.$sy.'">'.$sy.'</option>';
}
echo'</select>';
echo'<selectname="month"onchange="window.location=''.$url.'?year='.$this->year.'&month='+this.options[selectedIndex].value">';
for($sm=1;$sm<=12;$sm++){
$selected1=($sm==$this->month)?"selected":"";
echo'<option'.$selected1.'value="'.$sm.'">'.$sm.'</option>';
}
echo'</select>';
echo'</form>';
echo'</td>';
echo'<td><ahref="?'.$this->nextYear($this->year,$this->month).'">'.'>>'.'</a></td>';
echo'<td><ahref="?'.$this->nextMonth($this->year,$this->month).'">'.'>'.'</a></td>';
echo'</tr>';
}
}
?>test.php
代碼如下:
<style>
table{
border:1pxsolid#050;
}
.fontb{
color:white;
background:blue;
}
th{
width:30px;
}
td,th{
height:30px;
text-align:center;
}
form{
margin:0px;
padding:0px;
}
</style>
<?php
include"calendar.class.php";
$calendar=newCalendar;
$calendar->out();
?>
④ php萬年歷程序代碼
PHP代碼:
--------------------------------------------------------------------------------
<style>
.calendar
{
background-color: #FFFFFF;
border: 1px solid #003366;
}
.calendar .title
{
background-image: url("/theme/monthbg.gif");
line-height: 17pt;
background-color: #D8E2EC;
text-align: center;
vertical-align: middle;
font-family: Geneva, Verdana, Arial, sans-serif;
font-size: 13px;
font-weight: Bold;
color: #252216;
}
.calendar .head
{
background-image: url("dayBg.gif");
font-family: Geneva, Verdana, Arial, sans-serif;
font-size: 10px;
font-weight: Bold;
color: #433D27;
}
.calendar tbody
{
line-height: 11pt;
background-color: #F5F4D3;
text-align: center;
vertical-align: middle;
}
.calendar td
{
font-family: Geneva, Verdana, Arial, sans-serif;
font-size: 10px;
line-height: 15pt;
text-align: center;
vertical-align: middle;
width: 25px;
}
.calendar .weekday
{
background-color: #e0e0e0;
}
.calendar .weekend
{
background-color: #d0d0d0;
}
.calendar .today
{
background-color: #f7bebd;
}
.calendar .exmonth
{
background-color: #eeeeee;
}
.calendar a
{
text-decoration: none;
cursor: hand;
}
</style>
<?php
// 顯示某天所在月份的日歷
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;
}
?>
⑤ php中將一年12個月的日歷全部輸出。如何做
<?php
//SKY8G提供
function cal_days_in_year($year){
$days=0;
for($month=1;$month<=12;$month++){
$days = $days + cal_days_in_month(CAL_GREGORIAN,$month,$year);
}
return $days;
}
//閏年
echo "這是閏年一年有:".cal_days_in_year(2000)."天";
echo "\n";
//平年
echo "這是平年一年有:".cal_days_in_year(1999)."天";
echo "\n";
//2019年
echo "今年2019年有:".cal_days_in_year(date('Y',time()))."天";
echo "\n";
//接下來我們是用php的內置函數cal_days_in_month()
$d=cal_days_in_month(CAL_GREGORIAN,2,2010);
echo "2010 年平年 2 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,2,2000);
echo "2000 年閏年 2 月有 $d 天。";
echo "\n";
$d=cal_days_in_month(CAL_GREGORIAN,4,2010);
echo "2010 年平年 4 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,4,2000);
echo "2000 年閏年 4 月有 $d 天。";
echo "\n";
$d=cal_days_in_month(CAL_GREGORIAN,8,2010);
echo "2010 年平年 8 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,8,2000);
echo "2000 年閏年 8 月有 $d 天。";
//詳情如果想了解詳情去sky8g網觀看,希望對你有幫助!