JavaScript toLocaleTimeString() | Get the Time as String using Locale Conventions

The JavaScript toLocaleTimeString() method is used to get the time (using the locale conventions) as string. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <p id="xyz"></p>

   <script>
      const d = new Date();
      let timeLocale = d.toLocaleTimeString();
      document.getElementById("xyz").innerHTML = timeLocale;
   </script>

</body>
</html>
Output

JavaScript toLocaleTimeString() Syntax

The syntax of the toLocaleTimeString() method in JavaScript is:

x.toLocaleTimeString()

where x must be an object of the Date() constructor.

The toLocaleTimeString() method returns a string which will be the time using the locale conventions.

Please note: To get the date using local conventions, use toLocaleDateString().

Please note: To get the complete date using local conventions, use toLocaleString().

Please note: To display date in format dd-mm-yyyy, refer to its separate example.

Please note: To display time in format hh:mm:ss, refer to its separate example.

Please note: To display time in format hh:mm:ss AM/PM, refer to its separate example.

JavaScript Online Test


« Previous Tutorial Next Tutorial »



Like/Share Us on Facebook 😋