Monday, October 11, 2010

Javascript , YUI, Dates and Datatable

I've had some issues with pushing strings in JSON to a browser and having the browser parse them correctly.  Some browsers will take strings as argument, some want numbers -- it's a bit confusing.  To avoid all confusion, I recommend making a new date and then setting the values, rather than using the ambiguous constructors, which are implemented differently on different browsers.

As an example

new Date("2010, 12, 25");

and

new Date("12 25,2010");

both yield a date in Firefox, but not in IE.

Better is to do this:

Date d = new Date();
d.setFullYear(int year,int month,int day);  

Note that month is 0 based, so 0 is January, 11 is December.

No comments :