js acquisition date n days after the specified date

function addDays(date, days,seperator='-') {
  let oDate = new Date(date).valueOf();
  let nDate = oDate + days * 24 * 3600 * 1000;
  nDate = new Date(nDate);
  let y = nDate.getFullYear().toString().padStart(2, 0);
  let m = (nDate.getMonth() + 1).toString().padStart(2, 0);
  let d = nDate.getDate().toString().padStart(2, 0);
  return `${y}${seperator}${m}${seperator}${d}`
}

 

 

addDays('2019-06-03 09:30:30',6)
  "2019-06-09"

Guess you like

Origin www.cnblogs.com/zeng-zhi/p/10971953.html