this uses the prototype function '$' which is a helper for the standard js function 'getElementByID'. function showClock(element) { if ($(element)) { var thetime = new Date() var hour = thetime.getHours() var mins = thetime.getMinutes() var secs = thetime.getSeconds() var month = thetime.getMonth() + 1 var day = thetime.getDate() var year = thetime.getYear() if (secs < 10) secs = '0' + secs if (mins < 10) mins = '0' + mins if (hour < 10) hour = '0' + hour if (day < 10) day = '0' + day if (month < 10) month = '0' + month if (year <= 99) year = '19' + year if ((year > 99) && (year < 2000)) year += 1900 time = hour + ':' + mins + ':' + secs iso_date = year + '-' + month + '-' + day $(element).innerHTML = iso_date + ' ' + time } setTimeout('showClock("' + element + '")', 1000) }
hi this may help you, try this code <html> <head> <script type="text/javascript"> function startTime() { var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); // add a zero in front of numbers<10 m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTime()',500); } function checkTime(i) { if (i<10) { i="0" + i; } return i; } </script> </head> <body onload="startTime()"> <div id="txt"></div> </body> </html>