Sometimes, we want to get locale short date format using JavaScript.
In this article, we’ll look at how to get locale short date format using JavaScript.
How to get locale short date format using JavaScript?
To get locale short date format using JavaScript, we use the toLocaleDateString
method.
For instance, we write
const date = new Date();
const options = {
weekday: "short",
year: "numeric",
month: "2-digit",
day: "numeric",
};
console.log(date.toLocaleDateString("en", options));
to call toLocaleDateString
with the locale string and the options
which sets the returned date string to have the short date format.
Conclusion
To get locale short date format using JavaScript, we use the toLocaleDateString
method.