// JavaScript Document
function Clock(){
var objTime = new Date();
var nowYear = objTime.getFullYear();
var nowMonth = objTime.getMonth()+1;
var nowDay = objTime.getDate();
var nowHours = objTime.getHours();
var nowMinutes = objTime.getMinutes();
var nowSeconds = objTime.getSeconds();
if (nowMonth<10) nowMonth=’0′+nowMonth;
if (nowDay<10) nowDay=’0′+nowDay;
if (nowMinutes<10) nowMinutes=’0′+nowMinutes;
if (nowSeconds<10) nowSeconds=’0′+nowSeconds;
var noTimeVal = ‘ ’+nowYear+’-'+nowMonth+’-'+nowDay+’ ’+nowHours+’:'+nowMinutes+’:'+nowSeconds+’ ’;
try{
if (document.getElementById(‘Clock’) == undefined){
document.write(‘<div id="Clock">’);
document.write(‘</div>’);
document.getElementById(‘Clock’).innerHTML = noTimeVal;
} else {
document.getElementById(‘Clock’).innerHTML = noTimeVal;
}
} catch(e){alert(noTimeVal);}
setTimeout(‘Clock()’, 1000);
}
然后在页面中想要显示的地方调用 :
<script language="javascript">Clock("Clock");</script>