Categories
JavaScript Answers

How to get locale short date format using JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *