1

What I'm trying to do is to add 50 minutes to the current date I get, so I want to get the date and then get the time and then add 50 minutes. I want to check if I'm doing it the right way:

d = new Date();
dateAfter50min = d.setDate(d.getMinutes() + 50);
3
  • 1
    "I want to check if I'm doing it the right way" - This can be checked in seconds with a simple console.log()
    – Andreas
    Commented Sep 30, 2018 at 17:44
  • Yes, thank you :) I mean if there is a more proper way for doing this.
    – develop05
    Commented Sep 30, 2018 at 17:46
  • 1
    This might help: How to add 30 minutes to a JavaScript Date object? Commented Sep 30, 2018 at 17:51

2 Answers 2

1

If you want to just modify your current date object you can do it by following code

var d = new Date();
console.log(d);
d.setMinutes(d.getMinutes() + 50);
console.log(d);

1
  • This is just exactly what the OP posted.
    – RobG
    Commented Oct 1, 2018 at 2:11
0

If you want to create a new Date by adding minutes to an existing the date, you can get the time in milliseconds, and then add the minutes converted to milliseconds - minutes * 60 * 1000:

const d = new Date();
const dateAfter50min = new Date(d.getTime() + 50 * 60 * 1000);

console.log(d);
console.log(dateAfter50min);

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.