Lan*_*ard 3 javascript datetime
是否有一个帮助程序库用于执行这些类型的日期计算,如在Rails中?
Date.today.end_of_week
Run Code Online (Sandbox Code Playgroud)
Har*_*men 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() );
Run Code Online (Sandbox Code Playgroud)