Getting what is the first day of the week based on Locale with momentJs

Using momentJs, can I get the first day of the week (Monday (1), Sunday (7) ...) based on Locale without creating a new moment?

I know that I can access what is the first day of the week for the current language:

moment.locale('uk'); moment().startOf('week').isoWeekday(); //Returns 1 moment.locale('en'); moment().startOf('week').isoWeekday(); //Returns 7 

But I think this is a little ugly ...

  • Creating a momentjs object.
  • Go to the first date of the week.
  • Permission of the week.

Any better idea? thanks!

+5
source share
3 answers

This question has the correct answer in the currentjs current API:

 moment.localeData('en-us').firstDayOfWeek(); 

As the OP requested, there is no need for an instance of the moment (), nor is it the ugliness of going to the "beginning", a simple simple use of their localeData.

Please note that you may need to download the + locale + locale file, which is significantly larger (44kb) than just the moment (about 12kb).

It seems that from version 2.2.0 more information can be found in their documents: http://momentjs.com/docs/#/i18n/locale-data/

+12
source

Looks like you wanted to know the start level of the week ( startOf('week') ) and return its value as isoWeekday , not a date or something else? In this case, your question is the answer.

 moment().startOf('week').isoWeekday(); 
+4
source

Looks like you can just do moment (). locale ('us'). weekday (0) since version 2.1.0 http://momentjs.com/docs/#/get-set/weekday/

0
source

Source: https://habr.com/ru/post/1205883/


All Articles