1. 程式人生 > >JS計算日期加天數後的日期(起始日期+有效天數=截至日期)

JS計算日期加天數後的日期(起始日期+有效天數=截至日期)

 /**
  * 優惠券有效期
  * startDate:起始日期
  * valueTime:有效天數
  */
 function transferCouponValueTime(startDate,valueTime){
	 var date = new Date(startDate);
	 var newDate = new Date(date.getFullYear(),date.getMonth(),date.getDate()+valueTime);
	 var year1 = date.getFullYear();
	 var month1 = date.getMonth()+1;
	 var day1 = date.getDate();
	 var year2 = newDate.getFullYear();
	 var month2 = newDate.getMonth()+1;
	 var day2 = newDate.getDate();
	 return "<span>"+year1+"</span>-<span>"+month1+"</span>-<span>"+day1+"</span>一<span>"
	 						+year2+"</span>-<span>"+month2+"</span>-<span>"+day2+"</span>";
	 
 }