JavaScript toLocaleString

JavaScript toLocaleString function is one of the Date Function, which converts the given date and time to a string using system locale conversation. The basic syntax of the JavaScript toLocaleString function is:

 Date.toLocaleString()

JavaScript toLocaleString Function Example

The following example helps you understand the JavaScript to locale String Function. Here, we are using this function to convert today’s date and time to a string using system locales.

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

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

Date and Time: Fri Nov 09 2018 12:04:18 GMT+0530 (Indian Standard Time)
After toLocaleString() = 09/11/2018 12:04:18

JavaScript to Locale String Function Example 2

This JavaScript toLocaleString example returns the string representation date and time in a custom date and time using system locales.

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

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