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

我得到一个currentDate与:

  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);
console.log(myDate)


Demo

编辑

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

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/

10-12 16:28