Categories
JavaScript Answers

How to get localized day of week with JavaScript?

Spread the love

Sometimes, we want to get localized day of week with JavaScript.

In this article, we’ll look at how to get localized day of week with JavaScript.

How to get localized day of week with JavaScript?

To get localized day of week with JavaScript, we can use the date’s toLocaleString method.

For instance, we write:

const d = new Date();
const dStr = d.toLocaleString(window.navigator.language, {
  weekday: 'long'
});
console.log(dStr)

to call d.toLocaleString with the language of the device the code is running on and an object with weekday set to 'long' to return a localize string of the current date.

Conclusion

To get localized day of week with JavaScript, we can use the date’s toLocaleString 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 *