MathCurvesSurfacesWallpaper GroupsGallerySoftwarePOV-Ray
ProgramingLinuxPerl PythonHTMLCSSJavaScriptPHPJavaLang DesignEmacsUnicode ♥

JavaScript Example: Print Current Time

,

This page is a JavaScript example that prints the current time.

Sample

to show time.

Code

First, the “Click Me” button is a plain HTML tag, like this:

<p><button id="id39018">Click Me</button> to show time.</p>

The JavaScript is like this:

function myGetTime() {
    var dd = new Date();
    var hh = dd.getHours();
    var mm = dd.getMinutes();
    var ss = dd.getSeconds();
    alert("The time is now: " + hh + ":" + mm + ":" + ss);
}

document.getElementById("id39018").onclick = myGetTime;
blog comments powered by Disqus