time and 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
 
T

Trevor Lawrence

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();">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top