gpt4 book ai didi

Javascript "end of week"日期计算?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:54:11 25 4
gpt4 key购买 nike

是否有像 Rails 中那样进行这些类型的日期计算的辅助库?

Date.today.end_of_week

最佳答案

没有内置函数,但您可以定义自己的函数:

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() );

关于Javascript "end of week"日期计算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4248456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com