Date toTimeString() Method - Javascript Date

Javascript examples for Date:toTimeString

Description

The toTimeString() method converts the time portion of a Date object to a string.

Parameters

None

Return Value:

A String, representing the time as a string

The following code shows how to Convert the time portion of a Date object to a string:

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  ww  .  j  a  v a2 s.  com
    var d = new Date();
    var n = d.toTimeString();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials