Home >>JavaScript Date Object Methods >JavaScript toLocaleDateString() Method

JavaScript toLocaleDateString() Method

JavaScript toLocaleDateString() Method

JavaScript toLocaleDateString() methodis an inbuilt method in JavaScript which is used to converts the date(not the time) of a Date object in the form of string.

Syntax:
Date.toLocaleDateString()

Browser Support

Method Chrome Edge Firefox Safari Opera
toLocaleDateString() Yes Yes Yes Yes Yes
Here is an Example of JavaScript toLocaleDateString() Method:
<html>
<body>
<script>
var d=new Date();
document.writeln(d.toDateString());
</script>
</body>
</html>
Output:
Example 2:
<html>
<body>
<button onclick="mytoLocaleDstring()">click me</button>
<p id="Dstring"></p>
<script>
function mytoLocaleDstring() 
{
  var x = new Date();
  var y = x.toLocaleDateString();
  document.getElementById("Dstring").innerHTML = y;
}
</script>
</body>
</html> 
Output: