Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 66
    This solution doesn't take daylight savings into account. So, for example, this will return the same date, 23 hours later: new Date(new Date('11/4/2012').getTime() + 86400000) Commented Mar 20, 2012 at 14:55
  • 8
    @NoahMiller The problem which you bring up could be a feature not a bug! Adding 24 hours per day is sometimes the right thing to do, with the goal of knowing the resulting time based on DST. The date that your example returns has a time value of 11pm on November 4th which is what 24 hours later is on that particular day. The original poster asked about datetime which would seem to indicate some desire for correct times of the day. This answer is correct if you are in the case when your goal is the time 24 hours later. Commented Jun 23, 2014 at 15:12
  • 6
    I agree Noah, var d2 = new Date(d1.valueOf() + 24 * 60 * 60 * 1000) does what it says, adds a full day worth of ticks to a date. Commented Jul 18, 2014 at 16:44
  • 9
    This is absolutely correct for some cases (for example for 1 day cookies) and a simpler solution than most of the others. I dont get why it has so many downvotes and so few upvotes :/ Commented Nov 6, 2014 at 12:05
  • 2
    This answer is correct if (and only if) your date represents a UTC date/time or if you only want to add 24-hour days. Some other answers (AnthonyWJones's) are correct if (and only if) your date represents local time. The thing to understand is that a JavaScript Date represents an absolute moment in time, and they DO NOT have a time zone, so you must choose the correct method to use based on the time zone that you know (in your mind) the date represents. Commented Apr 15, 2021 at 0:22