我正在尝试用javascript编写代码,以便从今天开始两周(2周)的日期。有任何建议或帮助吗?
答案 0 :(得分:0)
首先获取当前日期,然后添加14天(2周),最后获得该周的最后一天:
// Get todays day
var now = new Date();
// Add 2 weeks
now.setTime( now.getTime() + 14 * 86400000 );
// Then go to the last day of that week
var fortnight = new Date(now.setDate(now.getDate() - now.getDay()+6));
console.log(fortnight);

答案 1 :(得分:0)
使用以下功能,您可以获得任何日期的两周日期。
function getFortNightDate(sDate){
var param = [];
var objDate = new Date();
param.todayDate = objDate.getFullYear() + '-' + ("0" + (objDate.getMonth() + 1)).slice(-2) + '-' + ("0" + (objDate.getDate())).slice(-2);
param.timeDiff = Math.abs(new Date(param.todayDate).getTime() - new Date(sDate).getTime());
param.diffDays = Math.ceil(param.timeDiff / (1000 * 3600 * 24));
param.dayCount = (14 - (param.diffDays % 14)) - 1;
objDate.setDate(objDate.getDate() + param.dayCount);
objDate = objDate.getFullYear() + '-' + ("0" + (objDate.getMonth() + 1)).slice(-2) + '-' + ("0" + (objDate.getDate())).slice(-2);
return objDate;
}