Starting the week on Monday with isoWeekday()
You just need to replace begin.startOf('isoWeek');
with begin.startOf('week');
.
Moment.js set week start on Monday
Add this to your code
moment.updateLocale('en', {
week: {
dow : 1, // Monday is the first day of the week.
}
});
moment.updateLocale('en', { week: { dow : 1, // Monday is the first day of the week. }});
var weeknumber = moment("2016-01-02", "YYYY-MM-DD").week();var weeknumber2 = moment("2016-01-03", "YYYY-MM-DD").week();console.log("02 is in week " + weeknumber);console.log("03 is in week " + weeknumber2);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
Using moment's isoWeekday to create a date grid
According to some pieces put together from https://momentjs.com/docs/#/customization/ and https://momentjs.com/docs/#/i18n/changing-locale/, you can use moment.updateLocale
to override the locale configuration globally, like so:
moment.updateLocale('en', { week: { dow: 6 //week starts on saturday }});
Determine first day of a week by a given date in moment js
The correct answer will be:
var begin = moment().subtract(1, 'week').startOf('week').format("YYYY MM DD");
var end = moment().subtract(1, 'week').endOf('week').format("YYYY MM DD");
Thanks to help by @MattJohnson
Change start of the week to Monday
OK, I got it.
Instead of trying to get explicit day as start of the week, startOf('isoWeek')
should be used.
So instead of
date = this.state.month.clone().startOf("month").add("w" - 1).day(0),
I did:
date = this.state.month.clone().startOf("month").add("w"-1).startOf('isoWeek'),
and now it looks right:
How to get count of days when week starts from Monday till current date in Python
According to the documentation isoweekday should do the trick
import datetime
dt = datetime.datetime.now()
dt.isoweekday()
returns 4 on Thursday
Related Topics
React How to Fix Failed Prop Type - Invalid Prop of Type String Expected Object
How to Pass Checkbox State to Onclick Function in React
Automatically Refreshing Page Every 60 Seconds Using JavaScript
Getting Selected Values from Dropdown Inside Table
Jquery Remove Special Characters from String and More
How to Set Profile Image as First Letters of First and Last Name
How to Replace a String With Square Brackets Using JavaScript Replace Function
Javascript to Hide Multiple Div
How to Get Dynamic Id Attribute for a Button Which Is Inside a 'While' Loop
Replace Unicode Matches in JavaScript
Want to Hide Menu by Clicking Outside the Menu Element
How to Remove a Parameter from a Url
How to Customize Header Cell in Pdf Using Jspdf-Autotable Plugin
Select Drop Down Text-Align Center in Safari