How to get first and last day of current week when days are in different months?
问题 For example, in the case of 03/27/2016 to 04/02/2016, the dates fall in different months. var curr = new Date; // get current date var first = curr.getDate() - curr.getDay(); var last = first + 6; // last day is the first day + 6 var firstday = new Date(curr.setDate(first)).toUTCString(); var lastday = new Date(curr.setDate(last)).toUTCString(); 回答1: The getDay method returns the number of the day in the week, with Sunday as 0 and Saturday as 6. So if your week starts on Sunday, just subtract