动态显示时间

< html  xmlns ="http://www.w3.org/1999/xhtml"  xml:lang ="en"  lang ="en" >
< head >
  
< title ></ title >
  
< script  type ="text/javascript" >
    
function  clock(){
        
var  nowtime = new  Date();
        
var  flag = " AM " ;
        
var  hours = nowtime.getHours();
        
if (hours > 12 ){
            hours
-= 12 ;
            flag
= " PM " ;
        }
        hours
= hours > 9 ? hours: " 0 " + hours;
        
var  minutes = nowtime.getMinutes();
        minutes
= minutes > 9 ? minutes: " 0 " + minutes;
        
var  seconds = nowtime.getSeconds();
        seconds
= seconds > 9 ? seconds: " 0 " + seconds;
        
var  disptime = hours + " : " + minutes + " : " + seconds + "   " + flag;
        document.getElementById(
" clock " ).innerHTML = disptime;
        setTimeout(
" clock() " , 1000 );
    }
  
</ script >
</ head >
< body >
< div  id ="clock" ></ div >
< script  type ="text/javascript" >
clock();
</ script >
</ body >
</ html >

你可能感兴趣的:(xml)