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

JavaScript toLocaleString() Method

JavaScript toLocaleString() Method

JavaScript toLocaleString() method is an inbuilt function in JavaScript which is used to converts a date object to a string, using the operating system’s local conventions.

Syntax:
Date.toLocaleString(locales, options)

Parameter Values

Parameter Description
locales It is an Optional parameter. It contains one or more language or locale tags specific format to use.
options It is an Optional parameter. It contains object and properties were you can set some properties like- timeZone, localeMatcher, weekday, month, year, minute, day, hour, second etc

Browser Support

Method Chrome Edge Firefox Safari Opera
toLocaleString() Yes Yes Yes Yes Yes
locales 24 11 29 10 15
options 24 11 29 10 15
Here is an Example of JavaScript toLocaleString() Method:
<html>
<body>
<button onclick="myLocalestring()">click me</button>
<p id="LS"></p>
<script>
function myLocalestring() 
{
  var d = new Date();
  var z = d.toLocaleString();
  document.getElementById("LS").innerHTML = z;
}
</script>
</body>
</html>
Output:

Example 2:
<html>
<body>
<script> 
var x = new Date(Date.UTC(2020, 2, 18, 4, 0, 0)); 
var y = { hour12: false }; 
document.write(x.toLocaleString("en-US")); 
document.write("<br>"); 
document.write(x.toLocaleString("en-US", y)); 
</script> 
</body>
</html>
Output: