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

JavaScript toLocaleTimeString() Method

JavaScript toLocaleTimeString() Method

JavaScript toLocaleTimeString() method is an inbuilt method in JavaScript which is used to returns the time portion from a given Date object as a string, using the current locale’s conventions.

Syntax:
Date.toLocaleTimeString()

Browser Support

Method Chrome Edge Firefox Safari Opera
toLocaleTimeString() Yes Yes Yes Yes Yes
Here is an example of JavaScript toLocaleTimeString() Method:
<html>
<body>
<button onclick="mytoLocaleDstring()">click me</button>
<p id="Dstring"></p>
<script>
function mytoLocaleDstring() 
{
  var x = new Date();
  var y = x.toLocaleDateString();
  document.getElementById("Dstring").innerHTML = y;
}
</script>
</body>
</html> 
Output:

Example 2:
<html>
<body>
<script> 
var A = new Date('January 25, 2017 16:45:34'); 
var B = A.toLocaleTimeString(); 
document.write(B); 
</script> 
</body>
</html>
Output: