Display current date & time at runtime into DIV tag

  1. <Html>  
  2.    <Head>  
  3.       <Tile>  
  4.       Sample Code</titel>  
  5.       <Script type="text/javascript">  
  6.          function DisplayDateTime()   
  7.          {  
  8.                var DateTime = new Date();           
  9.                var strYear= DateTime.getYear();           
  10.                var strMonth= DateTime.getMonth() +1;           
  11.                var strDay = DateTime.getDate();           
  12.                var strHours = DateTime.getHours();           
  13.                var strMinutes = DateTime.getMinutes();           
  14.                var strSeconds = DateTime.getSeconds();           
  15.                var tagDiv=document.getElementById("DivTag");           
  16.                tagDiv.innerText = "DD/MM/YYYY  HH:MM:SS";           
  17.                tagDiv.innerText = strDay + "/" + strMonth + "/" + strYear + "  " + strHours + ":" + strMinutes + ":" + strSeconds;           
  18.          }           
  19.       </Script>  
  20.    </Head>  
  21.    <Body bgcolor=#00ff00>  
  22.       <H3>DD/MM/YYYY       HH:MM:SS</H3>  
  23.       <input type="button" value="click" onclick="DisplayDateTime();">  
  24.       <H1>  
  25.          <Div id="DivTag"></div>  
  26.       </H1>  
  27.    </Body>  
  28. </Html>