计算指定天数后的日期

计算两个日期只差

var a =new Date("12,3,2018"), a1=a.getTime();

var b =new Date(), b1=b.getTime();

var c = a1-b1;
var d = c/(1000*60*60*24);  
Math.ceil(d);  //314

计算100天后的日期

var _date = new Date("12,3,2017"),
_t = _date.getDate(),
_m = _date.getMonth(),
_y = _date.getFullYear();

newdate = new Date(_y,_m,(_t+100)); //计算出的时间Tue Mar 13 2018 00:00:00 GMT+0800 (中国标准时间)

转换为 YY-MM-DD

date = newdate.getFullYear()+'-'+(newdate.getMonth()+1)+'-'+newdate.getDate();  //"2018-3-13"
dd = new Date(newdate);  //Tue Mar 13 2018 00:00:00 GMT+0800 (中国标准时间)
date = dd.getFullYear()+'-'+(dd.getMonth()+1)+'-'+dd.getDate();         //"2018-3-13"
date = newdate.getFullYear()+'-'+(newdate.getMonth()+1)+'-'+newdate.getDate();  //"2018-3-13"

你可能感兴趣的:(javascript)