是否有一个帮助程序库用于执行这些类型的日期计算,如在Rails中?
Date.today.end_of_week
答案 0 :(得分:10)
没有内置功能,但你可以自己定义:
Date.prototype.endOfWeek = function(){
return new Date(
this.getFullYear(),
this.getMonth(),
this.getDate() + 6 - this.getDay()
);
};
var now = new Date();
// returns next saturday; and returns saturday if it is saturday today.
console.log( now.endOfWeek() );
答案 1 :(得分:4)
答案 2 :(得分:1)