<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.js"></script><script>var now = moment(); // get "now"console.log(now.toDate()); // show original datevar thirty = moment(now).add(30,"minutes"); // clone "now" object and add 30 minutes, taking into account weirdness like crossing DST boundries or leap-days, -minutes, -seconds.console.log(thirty.toDate()); // show new date</script>
let getTimeAfter30Mins = () => {let timeAfter30Mins = new Date();timeAfter30Mins = new Date(timeAfter30Mins.setMinutes(timeAfter30Mins.getMinutes() + 30));};
function addTimeToDate(addedTime, date){let generatedTime = date.getTime();if(addedTime.seconds) generatedTime += 1000 * addedTime.seconds; //check for additional secondsif(addedTime.minutes) generatedTime += 1000* 60 * addedTime.minutes;//check for additional minutesif(addedTime.hours) generatedTime += 1000 * 60 * 60 * addedTime.hours;//check for additional hoursreturn new Date(generatedTime);}
Date.prototype.addTime = function(addedTime){return addTimeToDate(addedTime, this);}
let futureDate = new Date().addTime({hours: 16, //Adding one hourminutes: 45, //Adding fourty five minutesseconds: 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>
var dateAv = new Date();var endTime = new Date(dateAv.getFullYear(), dateAv.getMonth(), dateAv.getDate(), dateAv.getHours(), dateAv.getMinutes() + 30);
const first = new Date();console.log("first date :", first.toString());const second = new Date(first);const newMinutes = second.getMinutes() + 30;console.log("new minutes:", newMinutes);second.setMinutes(newMinutes);console.log("second date:", second.toString());