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.

10
  • 1
    I built a little calendar popup script in js, its on Github, maybe look through the code to see how the date object is interected with. Also, check Javascript Kit as its an awesome js reference, especially for the date object.
    – Christian
    Commented Jul 29, 2009 at 3:44
  • See also stackoverflow.com/questions/674721/… Commented May 21, 2011 at 15:12
  • 4
    All answers below that use a variation of date.setMinutes(date.getMinutes() + ...) will fail crossing over Daylight Saving boundaries. For example (assuming '2014-03-09' is a Daylight Saving boundary): var d = new Date('2014-03-09 01:59:00'), f = new Date(d.getTime()); d.setMinutes(d.getMinutes() + 30); d is now 30 minutes earlier, not later, than f.
    – Spig
    Commented Sep 12, 2014 at 15:07
  • 1
    @Spig: 30 minutes after 1:59 AM on DST boundary is 1:29AM. There is no error. If you print f and d, you'll see one says "GMT-0500" the other says "GMT-0400" (or whatever your time zone is). Also, if you call .getTime() on both f and d, you'll see that f is larger than d (i.e. later).
    – Kip
    Commented Sep 16, 2014 at 14:24
  • 1
    @Spig: interesting, tried it on Firefox and it worked. I think it falls into a grey area in the specification of how getMinutes() should work. 01:89 would become 02:29, which doesn't exist on the day you "spring forward". Chrome decides that should be 01:29, FF decides on 03:29. On the night when you "fall back", both browsers skip the "fall back" hour and jump ahead by 90 minutes, to 02:29. Here are some JSFiddle demos: "spring forward" / "fall back"
    – Kip
    Commented Sep 17, 2014 at 17:05