Home > Blockchain >  How to add some minutes to a Date format
How to add some minutes to a Date format

Time:07-11

So I'm working with the Google Calendar API and because the required date format I´m using the next way to get the starting time:

   const date1 = (mail._doc.Data[1].Date   'T'   mail._doc.Data[1].Time )
   const startingTime = new Date (date1)

This works and give me the next input that allows me to create the event in the calendar if I manually set the ending time

2022-07-15T21:23:00.000Z

That starting time will change depending of data in the server. For the ending time I would like for it to be the starting time (whatever it is) plus 45 minutes but I cant make it work.

Any help would be appreciated.

CodePudding user response:

const date = new Date();
console.log('Before : '   date);
date.setMinutes(date.getMinutes()   45); //adding 45 minutes
console.log('After : '   date);

CodePudding user response:

You can use timestamp in getTime() and use this formula to extend the current timestamp

45 minutes x 60 seconds x 1000 miliseconds

const startTime = new Date() //your starting time

console.log(startTime)

const startTimestamp = startTime.getTime()

//45 minutes x 60 seconds x 1000 miliseconds
const timeExtent = 45*60*1000

const endTime = new Date(startTimestamp   timeExtent)

console.log(endTime)

  • Related