I have a mysql table with dates in it (format: yyy-mm-dd). I then retrieve the dates and save them, however in the procures I change the dates format to make the user viewing easier for the task at hand. My issue is that when I get dates that are too far in the future (out a few months) they change and fall a day behind (otherwise it works fine). I spent a lot of time reading up on how the javascript date conversion works but I still do not have a firm understanding. Without what i wrote the date always comes in after the conversion a day behind. Also I am located in ohio. Here is what I have:
var x = offset*60000;
var time = new Date (item.start);
var time2=time.getTime();
var time3=time2+x;
var start = $.datepicker.formatDate('D, d M, yy', new Date (time3));
what is the issue here? Also if you could give a quick explanation for my education, that would be great. Thanks.
The problem is that the format you are passing to the
Dateconstructordoes not seem valid according to – https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date(i.e. a version of the ISO8601 extended format) is a valid ES5 format but is not correctly parsed by the browser.So something like this should be what you need:
http://jsfiddle.net/xfz6L/
Since
the problem seems to be that it is not a valid formatnot all browsers correctly parse the ISO8601 format, my solution is to use the string provided and manipulate it to work as a valid constructor.The easiest way I can think of is passing the “year”, “month”, and “day” in that order to the constructor.
To do that, you need to split the string by
-and then pass each array index to the constructor.The reason I subtract “1” from the month is that the range is from 0 to 11.