user3743266 user3743266 - 4 months ago 13
Javascript Question

Momentjs locale-specific weekdays()

In moment there is a function

moment.weekdays()
that returns an array from sunday - saturday

If I change my locale to EU where first day of the week is monday, for example finland(
moment.locale('fi')
)

the result of
moment.weekdays()
is still starting with (translated) sunday

also: this doesn't change moment.weekdays() result but changes moment.weekday(1) to monday

moment.updateLocale('fi', {
week: {
dow : 1 // Monday is the first day of the week
}
});


Is there a way to get weekdays for current locale in the right order(starting with monday) or is modifying the
moment.weekdays()
array myself the only way?

Answer Source

As of 2.13.0 you can pass a bool as the first parameter of the weekday functions. If true, the weekdays will be returned in locale specific order. For instance, in the Arabic locale, Saturday is the first day of the week

For your example in French, this would look like:

moment.locale("fr")
moment.weekdays(true)

output:

["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"]

link to documentation