Javascript examples for Date:getHours
Using getHours(), getMinutes(), and getSeconds() to display the time:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function addZero(i) { if (i < 10) { i = "0" + i; }// w ww . ja v a2 s.com return i; } function myFunction() { var d = new Date(); var x = document.getElementById("demo"); var h = addZero(d.getHours()); var m = addZero(d.getMinutes()); var s = addZero(d.getSeconds()); x.innerHTML = h + ":" + m + ":" + s; } </script> </body> </html>