使用getDayDate对象的方法,您可以知道星期几的数量(0 =星期日,1 =星期一等)。然后,您可以减去该天数加一,例如:function getMonday(d) { d = new Date(d); var day = d.getDay(), diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday return new Date(d.setDate(diff));}getMonday(new Date()); // Mon Nov 08 2010
不确定它如何比较性能,但这是有效的。var today = new Date();var day = today.getDay() || 7; // Get current day number, converting Sun. to 7if( day !== 1 ) // Only manipulate the date if it isn't Mon. today.setHours(-24 * (day - 1)); // Set the hours to day number minus 1 // multiplied by negative 24alert(today); // will be Monday或者作为一个功能:function getMonday( date ) { var day = date.getDay() || 7; if( day !== 1 ) date.setHours(-24 * (day - 1)); return date;}getMonday(new Date());