You can create one using Date.prototype.setDate():

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

var date = new Date();

console.log(date.addDays(5));

This takes care of automatically incrementing the month if necessary, as noted here. For example:

8/31 + 1 day will become 9/1.

The problem with using setDate directly is that it's a mutator and that sort of thing is best avoided. ECMA saw fit to treat Date as a mutable class rather than an immutable structure.

Answer from AnthonyWJones on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript | MDN
If the Date() constructor is called with one parameter which is not a Date instance, it will be coerced to a primitive and then checked whether it's a string. For example, new Date(undefined) is different from new Date(): js · console.log(new Date(undefined)); // Invalid Date ·
🌐
W3Schools
w3schools.com › js › js_dates.asp
W3Schools.com
February 4, 2026 - By default, JavaScript will use the browser's time zone and display a date as a full text string: You will learn much more about how to display dates, later in this tutorial. Date objects are created with the new Date() ...
Discussions

How to add days to Date?
When trying to calculate date time ... new Date(+yourDate + 30 * (24*60*60*1000)) 2020-01-24T16:49:52.157Z+00:00 ... And lots of other good stuff in there! Edit: jQuery reference removed thanks to aikeru's comment ... Yes, after futzing around with Plain ol' JS for too long, ... More on stackoverflow.com
🌐 stackoverflow.com
New Date("wtf") – How well do you know JavaScript's Date class?
This article is a good example. TS can't fix the underlying APIs, standard library etc · Best language would be the entire ecosystem, including standard library More on news.ycombinator.com
🌐 news.ycombinator.com
236
409
July 18, 2025
Is the Javascript date object always one day off? - Stack Overflow
In my Javascript app I have the date stored in a format like so: 2011-09-24 Now when I try using the above value to create a new Date object (so I can retrieve the date in a different format), the... More on stackoverflow.com
🌐 stackoverflow.com
Incorrect date shown in new Date() in JavaScript - Stack Overflow
This is what I get in chrome console. I pass "2016-09-05"(YYYY-MM-DD) as the date and it shows me Sept 4,2016 as the date. Another constructor shows the right date Passing it comma separated needs More on stackoverflow.com
🌐 stackoverflow.com
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
This also applies to dates specified with the date time string format. When attempting to set the local time to a time falling within an offset transition (usually daylight saving time), the exact time is derived using the same behavior as Temporal's disambiguation: "compatible" option. That is, if the local time corresponds to two instants, the earlier one is chosen; if the local time does not exist (there is a gap), we go forward by the gap duration. js · // Assume America/New_York local time zone // 2024-03-10 02:30 is within the spring-forward transition and does not exist // 01:59 (UTC-5
🌐
Visual Studio Code
code.visualstudio.com
Visual Studio Code - The open source AI code editor
"true" : undefined} > <div> <div class="mail-item-subject truncate">{e.subject}</div> <div class="mail-item-snippet truncate">{e.snippet}</div> </div> <time class="text-xs muted" datetime={e.date} title={new Date(e.date).toLocaleString()} > {new Date(e.date).toLocaleDateString(undefined, { month: "short", day: "numeric", })} </time> </div> <MailListItem email={e} isSelected={params.id === e.id} onOpen={open} /> )} </For> ); }
Top answer
1 of 16
1850

You can create one using Date.prototype.setDate():

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

var date = new Date();

console.log(date.addDays(5));

This takes care of automatically incrementing the month if necessary, as noted here. For example:

8/31 + 1 day will become 9/1.

The problem with using setDate directly is that it's a mutator and that sort of thing is best avoided. ECMA saw fit to treat Date as a mutable class rather than an immutable structure.

2 of 16
1171

Correct Answer:

function addDays(date, days) {
  var result = new Date(date);
  result.setDate(result.getDate() + days);
  return result;
}

Incorrect Answer:

This answer sometimes provides the correct result but very often returns the wrong year and month. The only time this answer works is when the date that you are adding days to happens to have the current year and month.

// Don't do it this way!
function addDaysWRONG(date, days) {
  var result = new Date(); // not instatiated with date!!! DANGER
  result.setDate(date.getDate() + days);
  return result;
}

Proof / Example

Check this JsFiddle

// Correct
function addDays(date, days) {
    var result = new Date(date);
    result.setDate(result.getDate() + days);
    return result;
}

// Bad Year/Month
function addDaysWRONG(date, days) {
    var result = new Date();
    result.setDate(date.getDate() + days);
    return result;
}

// Bad during DST
function addDaysDstFail(date, days) {
    var dayms = (days * 24 * 60 * 60 * 1000);
    return new Date(date.getTime() + dayms);    
}

// TEST
function formatDate(date) {
    return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
}

$('tbody tr td:first-child').each(function () {
    var (this);
    var ('<td/>').insertAfter($in).addClass("answer");
    var $outFail = $('<td/>').insertAfter(outDstFail = $('<td/>').insertAfter($outFail);
    var date = new Date($in.text());
    var correctDate = formatDate(addDays(date, 1));
    var failDate = formatDate(addDaysWRONG(date, 1));
    var failDstDate = formatDate(addDaysDstFail(date, 1));

    $out.text(correctDate);
    $outFail.text(failDate);
    $outDstFail.text(failDstDate);
    $outFail.addClass(correctDate == failDate ? "right" : "wrong");
    $outDstFail.addClass(correctDate == failDstDate ? "right" : "wrong");
});
body {
    font-size: 14px;
}

table {
    border-collapse:collapse;
}
table, td, th {
    border:1px solid black;
}
td {
    padding: 2px;
}

.wrong {
    color: red;
}
.right {
    color: green;
}
.answer {
    font-weight: bold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
    <tbody>
        <tr>
            <th colspan="4">DST Dates</th>
        </tr>
        <tr>
            <th>Input</th>
            <th>+1 Day</th>
            <th>+1 Day Fail</th>
            <th>+1 Day DST Fail</th>
        </tr>
        <tr><td>03/10/2013</td></tr>
        <tr><td>11/03/2013</td></tr>
        <tr><td>03/09/2014</td></tr>
        <tr><td>11/02/2014</td></tr>
        <tr><td>03/08/2015</td></tr>
        <tr><td>11/01/2015</td></tr>
        <tr>
            <th colspan="4">2013</th>
        </tr>
        <tr>
            <th>Input</th>
            <th>+1 Day</th>
            <th>+1 Day Fail</th>
            <th>+1 Day DST Fail</th>
        </tr>
        <tr><td>01/01/2013</td></tr>
        <tr><td>02/01/2013</td></tr>
        <tr><td>03/01/2013</td></tr>
        <tr><td>04/01/2013</td></tr>
        <tr><td>05/01/2013</td></tr>
        <tr><td>06/01/2013</td></tr>
        <tr><td>07/01/2013</td></tr>
        <tr><td>08/01/2013</td></tr>
        <tr><td>09/01/2013</td></tr>
        <tr><td>10/01/2013</td></tr>
        <tr><td>11/01/2013</td></tr>
        <tr><td>12/01/2013</td></tr>
        <tr>
            <th colspan="4">2014</th>
        </tr>
        <tr>
            <th>Input</th>
            <th>+1 Day</th>
            <th>+1 Day Fail</th>
            <th>+1 Day DST Fail</th>
        </tr>
        <tr><td>01/01/2014</td></tr>
        <tr><td>02/01/2014</td></tr>
        <tr><td>03/01/2014</td></tr>
        <tr><td>04/01/2014</td></tr>
        <tr><td>05/01/2014</td></tr>
        <tr><td>06/01/2014</td></tr>
        <tr><td>07/01/2014</td></tr>
        <tr><td>08/01/2014</td></tr>
        <tr><td>09/01/2014</td></tr>
        <tr><td>10/01/2014</td></tr>
        <tr><td>11/01/2014</td></tr>
        <tr><td>12/01/2014</td></tr>
        <tr>
            <th colspan="4">2015</th>
        </tr>
        <tr>
            <th>Input</th>
            <th>+1 Day</th>
            <th>+1 Day Fail</th>
            <th>+1 Day DST Fail</th>
        </tr>
        <tr><td>01/01/2015</td></tr>
        <tr><td>02/01/2015</td></tr>
        <tr><td>03/01/2015</td></tr>
        <tr><td>04/01/2015</td></tr>
        <tr><td>05/01/2015</td></tr>
        <tr><td>06/01/2015</td></tr>
        <tr><td>07/01/2015</td></tr>
        <tr><td>08/01/2015</td></tr>
        <tr><td>09/01/2015</td></tr>
        <tr><td>10/01/2015</td></tr>
        <tr><td>11/01/2015</td></tr>
        <tr><td>12/01/2015</td></tr>
    </tbody>
</table>

Find elsewhere
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - It is used for converting between Date JS objects and epoch timestamps and performing other advanced operations​. The most common way to create a Date object in JavaScript is by using the new Date() constructor, which returns the current date ...
🌐
Talent500
talent500.com › blog › javascript-date-object-methods-time-zones
JavaScript Date Object: Methods, Time Zones & Usage Guide
June 17, 2025 - In this example, new Date() creates a Date object that holds the current date and time based on the computer clock where your JavaScript code is running. However, if you run these same code snippets in different environments, you will see different ...
🌐
Dteenergy
startstop.dteenergy.com
How to Start, Stop, Move Electric & Gas Service | DTE Energy
Easily start, stop or move service within the DTE Energy service territory. Schedule your electric or natural gas service order online today!
🌐
Hacker News
news.ycombinator.com › item
New Date("wtf") – How well do you know JavaScript's Date class? | Hacker News
July 18, 2025 - This article is a good example. TS can't fix the underlying APIs, standard library etc · Best language would be the entire ecosystem, including standard library
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-date-objects
JavaScript Date Objects - GeeksforGeeks
July 11, 2025 - ... let cDate = new Date(); console.log(cDate.getFullYear()); // Gets the current year console.log(cDate.getMonth()); // Gets the current month (0-indexed) console.log(cDate.getDate()); // Gets the current day of the month console.log(cDate...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › now
Date.now() - JavaScript | MDN
The Date.now() static method returns the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.
🌐
The New Yorker
newyorker.com › culture › leukemia › a battle with my blood
Tatiana Schlossberg on Being Diagnosed with Leukemia After Giving Birth | The New Yorker
November 22, 2025 - On May 25, 2024, my daughter was born at 7:05 in the morning, ten minutes after I arrived at Columbia-Presbyterian hospital, in New York. My husband, George, and I held her and stared at her and admired her newness.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Representing_dates_times
Representing dates & times - JavaScript | MDN
A string representing a date, in many different forms. The exact forms supported differ among engines, but the following form is always supported: YYYY-MM-DDTHH:mm:ss.sssZ. For example, xmas95 = new Date("1995-12-25").
Top answer
1 of 16
550

There are several crazy things that happen with a JS DATE object that convert strings, for example consider the following date you provided

Note: The following examples may or may not be ONE DAY OFF depending on YOUR timezone and current time.

new Date("2011-09-24"); // Year-Month-Day
// => Fri Sep 23 2011 17:00:00 GMT-0700 (MST) - ONE DAY OFF.

However, if we rearrange the string format to Month-Day-Year...

new Date("09-24-2011");
// => Sat Sep 24 2011 00:00:00 GMT-0700 (MST) - CORRECT DATE.

Another strange one

new Date("2011-09-24");
// => Fri Sep 23 2011 17:00:00 GMT-0700 (MST) - ONE DAY OFF AS BEFORE.

new Date("2011/09/24"); // change from "-" to "/".
// => Sat Sep 24 2011 00:00:00 GMT-0700 (MST) - CORRECT DATE.

We could easily change hyphens in your date "2011-09-24" when making a new date

new Date("2011-09-24".replace(/-/g, '\/')); // => "2011/09/24".
// => Sat Sep 24 2011 00:00:00 GMT-0700 (MST) - CORRECT DATE.

What if we had a date string like "2011-09-24T00:00:00"

new Date("2011-09-24T00:00:00");
// => Fri Sep 23 2011 17:00:00 GMT-0700 (MST) - ONE DAY OFF.

Now change hyphen to forward slash as before; what happens?

new Date("2011/09/24T00:00:00");
// => Invalid Date.

I typically have to manage the date format 2011-09-24T00:00:00 so this is what I do.

new Date("2011-09-24T00:00:00".replace(/-/g, '\/').replace(/T.+/, ''));
// => Sat Sep 24 2011 00:00:00 GMT-0700 (MST) - CORRECT DATE.

UPDATE

If you provide separate arguments to the Date constructor you can get other useful outputs as described below

Note: arguments can be of type Number or String. I'll show examples with mixed values.

Get the first month and day of a given year

new Date(2011, 0); // Normal behavior as months in this case are zero based.
// => Sat Jan 01 2011 00:00:00 GMT-0700 (MST)

Get the last month and day of a year

new Date((2011 + 1), 0, 0); // The second zero roles back one day into the previous month's last day.
// => Sat Dec 31 2011 00:00:00 GMT-0700 (MST)

Example of Number, String arguments. Note the month is March because zero based months again.

new Date(2011, "02"); 
// => Tue Mar 01 2011 00:00:00 GMT-0700 (MST)

If we do the same thing but with a day of zero, we get something different.

new Date(2011, "02", 0); // Again the zero roles back from March to the last day of February.
// => Mon Feb 28 2011 00:00:00 GMT-0700 (MST)

Adding a day of zero to any year and month argument will get the last day of the previous month. If you continue with negative numbers you can continue rolling back another day

new Date(2011, "02", -1);
// => Sun Feb 27 2011 00:00:00 GMT-0700 (MST)
2 of 16
165

Notice that Eastern Daylight Time is -4 hours and that the hours on the date you're getting back are 20.

20h + 4h = 24h

which is midnight of 2011-09-24. The date was parsed in UTC (GMT) because you provided a date-only string without any time zone indicator. If you had given a date/time string w/o an indicator instead (new Date("2011-09-24T00:00:00")), it would have been parsed in your local timezone. (Historically there have been inconsistencies there, not least because the spec changed more than once, but modern browsers should be okay; or you can always include a timezone indicator.)

You're getting the right date, you just never specified the correct time zone.

If you need to access the date values, you can use getUTCDate() or any of the other getUTC*() functions:

var d,
  days;
d = new Date('2011-09-24');
days = ['Sun', 'Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat'];
console.log(days[d.getUTCDay()]);

🌐
ApexCharts
apexcharts.com › home
ApexCharts.js - Open Source JavaScript Charts for your website
March 7, 2020 - Get the latest news, updates and what's coming next!
Top answer
1 of 4
23

JavaScript will use the client's local time but it also has UTC / GMT methods. The following is from Mozilla:

The JavaScript Date object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed.

While methods are available to access date and time in both UTC and the localtime zone, the date and time are stored in the local time zone:

Note: It's important to keep in mind that the date and time is stored in the local time zone, and that the basic methods to fetch the date and time or its components all work in the local time zone as well.

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

2 of 4
4

What time zone does the Javascript new Date() use?

Date objects store the number of milliseconds since The Epoch (Jan 1st 1970 at midnight GMT). They have methods like getDay and getMonth and such that provide values in the local timezone, and also functions like getUTCDay and getUTCMonth that provide values in UTC (loosely, GMT).

If you're parsing a string, you need to be sure that the string is in a format that Date knows how to parse. The only defined format in the specification is a simplified derivative of ISO-8601: YYYY-MM-DDTHH:mm:ss.sssZ. But that was only added in ES5 (and then updated in ES2015 and ES2016). The time zone of the string is determined by whether it has a UTC offset indicator (Z, -08:00, +05:30, etc.) and whether it's date-only or date/time. Here are some examples:

function test(str) {
    const dt = new Date(str);
    const p = document.createElement("pre");
    p.textContent =
        `String: "${str}"\n` +
        `UTC:    ${dt.toISOString()}\n` +
        `Local:  ${dt.toLocaleString()}`
    ;
    document.body.appendChild(p);
}

// No UTC offset provided, date-only form => parsed as UTC:
test("2015-08-09");

// No UTC offset provided, date/time form => parsed as local time:
test("2015-08-09T09:32:54");

// Has UTC offset "Z" (for "no offset") => parsed as UTC:
test("2015-08-09T09:32:54.427Z");

// Has UTC offset -08:00 => parsed as UTC minus eight hours:
test("2015-08-09T09:32:54.427-08:00");


I don't recommend relying on it, but even though it's not specified, all major JavaScript engines will successfully parse the American-specific formats MM/DD/YYYY, MM/DD/YYYY hh:mm, MM/DD/YYYY hh:mm:ss, or MM/DD/YYYY hh:mm:ss.SSS (although the milliseconds portion is ignored by some). Note the order in the date portion: month, day, year. Having a UTC offset indicator is not broadly supported and will cause an error on most engines, so don't include one. Without one, all of those are parsed as local time (even the date-only one). Note that the date field separator must be / (08/09/2015), not - (08-09-2015).

function test(str) {
    const dt = new Date(str);
    const p = document.createElement("pre");
    p.textContent =
        `String: "${str}"\n` +
        `UTC:    ${dt.toISOString()}\n` +
        `Local:  ${dt.toLocaleString()}`
    ;
    document.body.appendChild(p);
}

test("08/09/2015");
test("08/09/2015 09:32");
test("08/09/2015 09:32:54");
test("08/09/2015 09:32:54.427");

But again: I don't recommend relying on that.

🌐
JetBrains
jetbrains.com › idea › whatsnew
What's New in IntelliJ IDEA
Monitoring and managing your AI resources just got a lot easier, as you can now view your remaining AI Credits, renewal date, and top-up balance directly inside IntelliJ IDEA.