gpt4 book ai didi

Javascript 天 +/- 从今天开始

转载 作者:行者123 更新时间:2023-11-29 18:19:56 25 4
gpt4 key购买 nike

对于日期选择器,我需要两个日期:来自:今天 - 7 天,至:今天 + 7 天。

我得到一个当前日期:

  var toDay = new Date();
var curr_date = toDay.getDate();
var curr_month = toDay.getMonth();
curr_month++;
var curr_year = toDay.getFullYear();
var toDay = (curr_month + "/" + curr_date + "/" + curr_year);

如何获取 7 days+7 days- 日期? 对应月份!

最佳答案

根据评论,您可以使用以下代码

var myDate = new Date();
myDate.setDate(myDate.getDate() + 7);
var nextWeekDate = ((myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myDate.getFullYear());

myDate = new Date();
myDate.setDate(myDate.getDate() -7 );
var prevWeekDate = ((myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myDate.getFullYear());

Modified Demo

关于Javascript 天 +/- 从今天开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19707957/

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