0

How can I get the date after three days from today in ISO format?

I can get today's date with the following code, but not sure about how to get the ISO date in three days.

const today = new Date().toISOString().substring(0, 10);
kohshiba
  • 317
  • 1
  • 3
  • 8
  • You just need to get the date and then call toISOString, possible duplicate of https://stackoverflow.com/questions/563406/add-days-to-javascript-date – Moshe Sommers Aug 20 '20 at 15:34
  • That gets the current UTC date, which might be different from your local date by ±1 day depending on when the code is run and the host timezone offset. – RobG Aug 20 '20 at 22:31

1 Answers1

-1

I made this script for you, so you can actually add or substract as much hours, minutes and seconds as you want!

function strtotime(date, addTime){
  let generatedTime=date.getTime();
  if(addTime.seconds) generatedTime+=1000*addTime.seconds; //check for additional seconds 
  if(addTime.minutes) generatedTime+=1000*60*addTime.minutes;//check for additional minutes 
  if(addTime.hours) generatedTime+=1000*60*60*addTime.hours;//check for additional hours 
  return new Date(generatedTime);
}

Date.prototype.strtotime = function(addTime){
  return strtotime(new Date(), addTime); 
}

let futureDate = new Date().strtotime({
    hours: 24 * 3, //Adding 3days
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
}).toISOString().substring(0, 10);

console.log( futureDate );
Adnane Ar
  • 683
  • 7
  • 11