Date toLocaleTimeString() Method - Javascript Date

Javascript examples for Date:toLocaleTimeString

Description

The toLocaleTimeString() method returns the time portion of a Date object as a string, using locale conventions.

Return Value:

A String, representing the time as a string

The following code shows how to return the time portion of a Date object as a string, using locale conventions:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//  w  w w .  j a va2s  .  c o  m
    var d = new Date();
    var n = d.toLocaleTimeString();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials