Home >>JavaScript Date Object Methods >JavaScript Date toTimeString() Method
JavaScript Date toTimeString() method in JavaScript is an inbuilt method which is used to converts the time portion of the given Date object to a string.
Syntax:Date.toTimeString()
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
toTimeString() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <button onclick="mytimestr()">click me</button> <p id="Tstr"></p> <script> function mytimestr() { var d = new Date(); var a = d.toTimeString(); document.getElementById("Tstr").innerHTML = a; } </script> </body> </html>
<html> <body> <script> var dateobj = new Date('November 24, 1997 08:40:45'); var Z = dateobj.toTimeString(); document.write(Z); </script> </body> </html>