JavaScript toLocaleDateString

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

 Date.toLocaleDateString()

JavaScript toLocaleDateString Function Example

We use JavaScript to locale Date String function to convert the data portion of today’s date to a string using system locales.

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

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

Date and Time: Fri Nov 09 2018 12:02:43 GMT+0530 (Indian Standard Time)
After toLocaleDateString() = 09/11/2018

JavaScript to Locale Date String Example 2

This JavaScript toLocaleDateString example returns the date of a custom date in a string format.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Date toLocaleDateString Function  </title>
</head>
<body>
    <h1> JavaScript toLocaleDateString Example </h1>
<script>
  var dt = Date(2005, 11, 14, 02, 19, 5);
  document.write("Date and Time : " + dt + "<br/>");

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