Javascript examples for Date:toLocaleTimeString
The toLocaleTimeString() method returns the time portion of a Date object as a string, using locale conventions.
A String, representing the time as a string
The following code shows how to return the time portion of a Date object as a string, using locale conventions:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w w w . j a va2s . c o m var d = new Date(); var n = d.toLocaleTimeString(); document.getElementById("demo").innerHTML = n; } </script> </body> </html>