Skip to main content
Better readability
Source Link
Adnane Ar
  • 683
  • 7
  • 12

I know that the topic is way too old. But I am pretty sure that there are some developpers who still need this, so I made this simple script for you. I hope you enjoy it!

Hello back, It's 2020 and I've added some modification hope it will help a lot better now!

Hello again, It is 2022 and I came back again to fix some issues and give a better naming for the methods & functions.

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

Date.prototype.addTime = function(addedTime){
  return addTimeToDate(addedTime, this);
}

let futureDate = new Date().addTime({
    hours: 16, //Adding one hour
    minutes: 45, //Adding fourty five minutes
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
});
<button onclick="console.log(futureDate)">Travel to the future</button>

I know that the topic is way too old. But I am pretty sure that there are some developpers who still need this, so I made this simple script for you. I hope you enjoy it!

Hello back, It's 2020 and I've added some modification hope it will help a lot better now!

Hello again, It is 2022 and I came back again to fix some issues and give a better naming for the methods & functions.

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

Date.prototype.addTime = function(addedTime){
  return addTimeToDate(addedTime, this);
}

let futureDate = new Date().addTime({
    hours: 16, //Adding one hour
    minutes: 45, //Adding fourty five minutes
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
});
<button onclick="console.log(futureDate)">Travel to the future</button>

I know that the topic is way too old. But I am pretty sure that there are some developpers who still need this, so I made this simple script for you. I hope you enjoy it!

Hello back, It's 2020 and I've added some modification hope it will help a lot better now!

Hello again, It is 2022 and I came back again to fix some issues and give a better naming for the methods & functions.

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

Date.prototype.addTime = function(addedTime){
  return addTimeToDate(addedTime, this);
}

let futureDate = new Date().addTime({
    hours: 16, //Adding one hour
    minutes: 45, //Adding fourty five minutes
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
});
<button onclick="console.log(futureDate)">Travel to the future</button>

added 12 characters in body
Source Link
Adnane Ar
  • 683
  • 7
  • 12

I know that the topic is way too old. But I am pretty sure that there are some developpers who still need this, so I made this simple script for you. I hope you enjoy it!

Hello back, It's 2020 and I've added some modification hope it will help a lot better now!

Hello again, It is 2022 and I came back again to fix some issues and give a better naming for the methods & functions.

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

Date.prototype.addTime = function(addedTime){
  return addTimeaddTimeToDate(thisaddedTime, addedTimethis);
}

let futureDate = new Date().addTime({
    hours: 16, //Adding one hour
    minutes: 45, //Adding fourty five minutes
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
});
<button onclick="console.log(futureDate)">Travel to the future</button>

I know that the topic is way too old. But I am pretty sure that there are some developpers who still need this, so I made this simple script for you. I hope you enjoy it!

Hello back, It's 2020 and I've added some modification hope it will help a lot better now!

Hello again, It is 2022 and I came back again to fix some issues and give a better naming for the methods & functions.

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

Date.prototype.addTime = function(addedTime){
  return addTime(this, addedTime);
}

let futureDate = new Date().addTime({
    hours: 16, //Adding one hour
    minutes: 45, //Adding fourty five minutes
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
});
<button onclick="console.log(futureDate)">Travel to the future</button>

I know that the topic is way too old. But I am pretty sure that there are some developpers who still need this, so I made this simple script for you. I hope you enjoy it!

Hello back, It's 2020 and I've added some modification hope it will help a lot better now!

Hello again, It is 2022 and I came back again to fix some issues and give a better naming for the methods & functions.

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

Date.prototype.addTime = function(addedTime){
  return addTimeToDate(addedTime, this);
}

let futureDate = new Date().addTime({
    hours: 16, //Adding one hour
    minutes: 45, //Adding fourty five minutes
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
});
<button onclick="console.log(futureDate)">Travel to the future</button>

deleted 9 characters in body
Source Link
Adnane Ar
  • 683
  • 7
  • 12

I know that the topic is way too old. But I am pretty sure that there are some developpers who still need this, so I made this simple script for you. I hope you enjoy it!

Hello back, It's 2020 and I've added some modification hope it will help a lot better now!

Hello again, It is 2022 and I came back again to fix some issues and give a better naming for the methods & functions.

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

Date.prototype.strtotimeaddTime = function(addTimeaddedTime){
  return strtotimeaddTime(this, addTimeaddedTime);
}

let futureDate = new Date().strtotimeaddTime({
    hours: 16, //Adding one hour
    minutes: 45, //Adding fourty five minutes
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
});
<button onclick="console.log(futureDate)">Travel to the future</button>

I know that the topic is way too old. But I am pretty sure that there are some developpers who still need this, so I made this simple script for you. I hope you enjoy it!

Hello back, It's 2020 and I've added some modification hope it will help a lot better now!

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(this, addTime);
}

let futureDate = new Date().strtotime({
    hours: 16, //Adding one hour
    minutes: 45, //Adding fourty five minutes
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
});
<button onclick="console.log(futureDate)">Travel to the future</button>

I know that the topic is way too old. But I am pretty sure that there are some developpers who still need this, so I made this simple script for you. I hope you enjoy it!

Hello back, It's 2020 and I've added some modification hope it will help a lot better now!

Hello again, It is 2022 and I came back again to fix some issues and give a better naming for the methods & functions.

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

Date.prototype.addTime = function(addedTime){
  return addTime(this, addedTime);
}

let futureDate = new Date().addTime({
    hours: 16, //Adding one hour
    minutes: 45, //Adding fourty five minutes
    seconds: 0 //Adding 0 seconds return to not adding any second so  we can remove it.
});
<button onclick="console.log(futureDate)">Travel to the future</button>

deleted 9 characters in body
Source Link
Adnane Ar
  • 683
  • 7
  • 12
Loading
added 205 characters in body
Source Link
Adnane Ar
  • 683
  • 7
  • 12
Loading
Source Link
Adnane Ar
  • 683
  • 7
  • 12
Loading