1. 程式人生 > >在網頁上獲取實時的時間和天氣

在網頁上獲取實時的時間和天氣

<script language="javascript">
function getCurDate()
{
 var d = new Date();
 var week;
 switch (d.getDay()){
 case 1: week="星期一"; break;
 case 2: week="星期二"; break;
 case 3: week="星期三"; break;
 case 4: week="星期四"; break;
 case 5: week="星期五"; break;
 case 6: week="星期六"; break;
 default: week="星期天";
 }
 var years = d.getFullYear();
 var month = add_zero(d.getMonth()+1);
 var days = add_zero(d.getDate());
 var hours = add_zero(d.getHours());
 var minutes = add_zero(d.getMinutes());
 var seconds=add_zero(d.getSeconds());
 var ndate = years+"年"+month+"月"+days+"日 "+hours+":"+minutes+":"+seconds+" ";
 var divT=document.getElementById("divT");
 divT.innerHTML= ndate;
}
function add_zero(temp)
{
 if(temp<10) return "0"+temp;
 else return temp;
}
setInterval("getCurDate()",100);

</script>
 

<p><span class="search-timer"><font id="divT"></font></span></p>
<iframe width="186" scrolling="no" height="30" frameborder="0" allowtransparency="true" src="http://i.tianqi.com/index.php?c=code&id=1&icon=1&py=luohe&wind=0&num=1&site=14"></iframe>