Home >>JavaScript Date Object Methods >JavaScript Date toTimeString() Method

JavaScript Date toTimeString() Method

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()

Browser Support

Method Chrome Edge Firefox Safari Opera
toTimeString() Yes Yes Yes Yes Yes
Here is an Example of JavaScript toTimeString() Method:
<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>
Output:

Example 2:
<html>
<body>
<script> 
var dateobj = new Date('November 24, 1997 08:40:45');  
var Z = dateobj.toTimeString(); 
document.write(Z); 
</script>					 
</body>
</html>
Output:

No Sidebar ads