Javascript example current date and time
Today's date is: getDate(), getMonth(), getFullYear(). Example javascript date and time.
by ITpresent
HTML
<p>Today's date is:<br> <span id="x"></span></p>
<p>Current time: <br> <span id="y"></span></p>
<a href="https://itpresent.com/web/javascript/javascript_examples.php" target="_blank">Example javascript current date and time and stopwatch</a>
CSS
#x {
color: blue;
font-size: 35px;
}
#y {
color: red;
font-size: 35px;
}
a {
font-weight: bold;
}
p {
font-size: 25px;
font-weight: bold;
}
JavaScript
var x=new Date();
var a=document.getElementById('x');
a.innerHTML=x.getDate()+"/"+(x.getMonth()+1)+'/'+x.getFullYear();
function timeNow() {
var y=new Date();
var b=document.getElementById('y');
b.innerHTML=y.toLocaleTimeString();
}
setInterval(timeNow,1000);