time and date

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

whats the code, if there is one, to input the system time and date. Each time
the site is opened it will show the current time and date. In excel it's
=now() or =today() but I don't know how to do it in html
 
Richard said:
whats the code, if there is one, to input the system time and date. Each
time
the site is opened it will show the current time and date. In excel it's
=now() or =today() but I don't know how to do it in html

To set a date and time that updates every second , use this HTML

<body onload="setInterval(DateTime,1000);">

Current Date: <span id="hdate" class="red"></span><br />
Current Time: <span id="htime" class="red"></span>

with this JS

function DateTime() {
var now = new Date();

document.getElementById("hdate").innerHTML = now.toLocaleDateString();
document.getElementById("htime").innerHTML = now.toLocaleTimeString()
+ ' (UTC+' + (-now.getTimezoneOffset()*100/60) + ')';
}

If you only want the time and date once, use
<body onload="DateTime();">
 
Back
Top