Web >> Development >> Javascript >>  How to insert current date and time into a html page

<head> <META HTTP-EQUIV="REFRESH" content="10"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Cache-Control" content="no-cache"> <style type="text/css"> <!-- A { text-transofrm:none; text-decoration:none; color: #000000; } --> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function clock() { aMonthNames= ["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; if (!document.layers && !document.all) return; var digital = new Date(); var hours = digital.getHours(); var minutes = digital.getMinutes(); var seconds = digital.getSeconds(); var amOrPm = "AM"; var sDD = digital.getDate(); var sMM = aMonthNames[1 digital.getMonth()]; var sYY = digital.getFullYear(); var sFullDate = sDD '-' sMM '-' sYY; if (hours > 11) amOrPm = "PM"; if (hours > 12) hours = hours - 12; if (hours == 0) hours = 12; if (minutes <= 9) minutes = "0" minutes; if (seconds <= 9) seconds = "0" seconds; dispTime = sFullDate " " hours ":" minutes ":" seconds " " amOrPm; if (document.layers) { document.layers.pendule.document.write(dispTime); document.layers.pendule.document.close(); } else if (document.all) pendule.innerHTML = dispTime; setTimeout("clock()", 5); } // End --> </script> </HEAD> <BODY onLoad="clock()"> <span id="pendule" style="position:absolute;right:10;top:10;"></span> </body> </html>