JavaScript toLocaleTimeString

JavaScript toLocaleTimeString function converts the Time portion of a given date and time to a time string using system locale conversation. The syntax of the JavaScript toLocaleTimeString Date function is:

 Date.toLocaleTimeString()

JavaScript toLocaleTimeString Function Example

Here, we are using the JavaScript to locale Time String Function to convert the time portion of today’s date. And time to a time string using system locales.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Date toLocaleTimeString Function  </title>
</head>
<body>
    <h1> JavaScript toLocaleTimeString Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt + "<br/>");

  var x = dt.toLocaleTimeString();
  document.write("After toLocaleTimeString() = " + x);
</script>
</body>
</html>
JavaScript toLocaleTimeString Example

Date and Time: Mon Dec 31 2012 22:45:32 GMT+0530 (Indian Standard Time)
After toLocaleTimeString() = 22:45:32

JavaScript to Locale Time String Function Example 2

This JavaScript toLocaleTimeString example returns the time portion of a custom date and time in a string format.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Date toLocaleTimeString Function  </title>
</head>
<body>
    <h1> JavaScript toLocaleTimeString Example </h1>
<script>
  var dt = Date(2012, 11, 31, 22, 45, 32);
  document.write("Date and Time : " + dt + "<br/>");

  var x = dt.toLocaleTimeString();
  document.write("After toLocaleTimeString() = " + x);
</script>
</body>
</html>
JavaScript toLocaleTimeString 2