How do I add a date to DateTime?

Asked 1 years ago, Updated 1 years ago, 43 views

I want to add a date to the current DateTime in JavaScript, what should I do? Is there a function that JavaScript uses like AddDay on the dot net?

javascript date

2022-09-21 19:33

1 Answers

Well, I think you can make it like this and use it.

Date.prototype.addDays = function(days)
{
    var dat = new Date(this.valueOf());
    dat.setDate(dat.getDate() + days);
    return dat;
}

var dat = new Date();

alert(dat.addDays(5))


2022-09-21 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.