2

I'm trying to add 3 days in a date, like this:

var dat = new Date(2014,9,16);

Thu Oct 16 2014 00:00:00 GMT-0300 (Hora oficial do Brasil)

dat.setDate(19);

Sat Oct 18 2014 23:00:00 GMT-0300 (Hora oficial do Brasil)

Why this not returns this Sat Oct 19 2014 23:00:00 GMT-0300 (Hora oficial do Brasil)?

rayashi
  • 1,721
  • 3
  • 20
  • 28
  • @rpax I don't think this is a duplicate of that other bug; even if it were, there's a lot of confusion and misinformation in that bug. – Pointy Mar 20 '14 at 17:09

2 Answers2

2

I believe that the problem has to do with Brazilian daylight savings time rules. At midnight on 19 Oct in the parts of Brasil that do daylight savings time, the clock is set back an hour.

Try this:

var d = new Date(2014, 9, 16);
d.setHours(5); // 5 in the morning
d.setDate(19);
console.log(d);

It must drive Brazilians a little crazy to have the DST cutover happen at midnight.

Pointy
  • 405,095
  • 59
  • 585
  • 614
1

Check this demo jsFiddle

Try this way,

var date = new Date(2014,9,16);        // Get user define Date
date.setDate(date.getDate() + 3);     // add 3 days to user define date
alert(date);
Jaykumar Patel
  • 26,836
  • 12
  • 74
  • 76