Okay, I have heard about it but I can confirm now that the Javascript Date functionality is a disaster zone. And I have created a monster out of it. I have this Program :
A JSON object contains list of holiday dates and its respective label.
I need to find out the date of 5 business days from today (excluding saturday, sunday and holiday if any which is contained in the JSON object.) Good stuff so far. Then this 5 business days’ date is going to be devoured by the jquery calender as a default selected date which is not included in the fiddle as it is irrelevant. (Note: the start date on the calender is tommorow’s date) Good stuff again. THEN, comes this part: If it is before noon today, I can select tommorow else start date is day after tommorow. I’m elaborating this because it is included in this fiddle.
So the problem is multiple initialization of the function which handles above functionality is not producing consistent result. It was calculating 5 business days on my system, but when i made this fiddle, it is calculating 4. The date of “5th” business days is incremental by 1 on each call.
Anyone!
Your problem is probably caused by timezone issues.
Whenever possible you should use
new Date(y, m, d)to create a date object, rather than supplying a string. In particular, I’ve found that you get a date relative to 00:00 UTC if you specify a string in formatyyyy-mm-ddbut one relative to local midnight if you useyyyy/mm/dd.In any event, I would suggest a different approach:
d.setDate(d.getDate() + 1)That should give you the next 10 business days in your array. Pick the ones you need to fill out your date picker.