Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Momentjs locale-specific weekdays() [duplicate]

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?

like image 975
user3743266 Avatar asked Jun 18 '17 19:06

user3743266


People also ask

Is MomentJS deprecated?

Moment construction falls back to js Date. This is discouraged and will be removed in an upcoming major release. This deprecation warning is thrown when no known format is found for a date passed into the string constructor.

Is Moment () the same as new date ()?

To get the current date and time, just call moment() with no parameters. var now = moment(); This is essentially the same as calling moment(new Date()) . Note: From version 2.14.0, moment([]) and moment({}) also return now.

What is _D and _I in moment?

_i will never be a moment object. _i can also be undefined, in the case of creating the current moment with moment() . _d is the instance of the Date object that backs the moment object. If you are in "local mode", then _d will have the same local date and time as the moment object exhibits with the public API.

How do I set a moment in locale?

You set locale with moment. locale('de') , and you create a new object representing the date of now by moment() (note the parenthesis) and then format('LLL') it. The parenthesis is important.


1 Answers

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

like image 145
Matthew Costi Avatar answered Oct 08 '22 01:10

Matthew Costi