I'd like to get the names of the days of the weeks in JavaScript, localized to the user's current language; preferably with something a bit nicer than what I'm using now:
var weekDays = [];
var d = new Date();
while(d.getDay() > 0) {
d.setDate(d.getDate() + 1);
}
while(weekDays.length < 7) {
weekDays.push(d.toLocaleDateString().match(/\w+/)[0]);
d.setDate(d.getDate() + 1);
}
Is there an easy way to do this? Or am I just going to have to provide date strings for as many locales as I can?
I use Date.toLocaleString()
, for example:
d = new Date();
d.toLocaleString(window.navigator.language, {weekday: 'long'});
or
d.toLocaleString('sk-SK', {weekday: 'short'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With