Home >>JavaScript Date Object Methods >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()
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
toLocaleTimeString() | Yes | Yes | Yes | Yes | Yes |
<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>
<html> <body> <script> var A = new Date('January 25, 2017 16:45:34'); var B = A.toLocaleTimeString(); document.write(B); </script> </body> </html>