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)?

1
  • @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. Commented Mar 20, 2014 at 17:09

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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); 

6 Comments

but why wait i show you demo, i accept my type mistake but i do.
OK that's better, but it's still basically the same as what the OP is doing (16 + 3 is 19).
I tryed this but return the same result : Sat Oct 18 2014 23:00:00 GMT-0300 (Hora oficial do Brasil), instead Sat Oct 19 2014 23:00:00 GMT-0300 (Hora oficial do Brasil)
ok thank @Pointy to give more minutes now you check it this is work.
@rayashi right, because you're still in Brasil :)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.