Using momentJs, is possible to get the first day of the week (Monday(1), Sunday(7)...) based on Locale without creating a new moment?
I know I can access what is the first day of the week for the current locale with:
moment.locale('uk');
moment().startOf('week').isoWeekday(); //Returns 1
moment.locale('en');
moment().startOf('week').isoWeekday(); //Returns 7
But I think it's a bit ugly...
Any better idea? Thx!
This question has a proper answer in momentjs's current API:
moment.localeData('en-us').firstDayOfWeek();
As OP asked - no instance of moment() needed, also no ugliness of going to "start of", just plain simple use of their localeData.
Note, that it might be required to download the moment+locale file which is significantly larger (44kb) than moment only (about 12kb).
Seems to be the case from version 2.2.0, more info can be found on their docs: http://momentjs.com/docs/#/i18n/locale-data/
Looks to me that you wanted to get a locale aware start of week (startOf('week')
) and return its value as an isoWeekday
, not the date or anything? In that case your question is the answer.
moment().startOf('week').isoWeekday();
It looks like you can just do moment().locale('us').weekday(0) as of version 2.1.0 http://momentjs.com/docs/#/get-set/weekday/
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