Cross Browser date wackiness

Discussion created by evtguy on Aug 17, 2012
Latest reply on Aug 20, 2012 by evtguy
On the page I've been developing, I've been populating a datagrid with attributes from a feature layer. A few of the attributes are date fields. I found out the hard way about the the format of date values returned through the API so I looked for a function to properly format my dates and times back into xx/xx/xxxx and xx:xx ampm formats.

I settled on the following functions which use dojo:

function formatDate(value){
 var inputDate = new Date(value);
 return dojo.date.locale.format(inputDate, {
   selector: 'date',
   datePattern: 'MM/dd/yyyy' 

function formatTime(value){
 var inputTime = new Date(value);
 return dojo.date.locale.format(inputTime, {
   selector: 'date',
   datePattern: 'K:mm a' 

The routines are used in a formatter() function for one of my columns in the datagrid like this:

var rowdata = this.grid.getItem(rowIndex);
var theClosureDate = rowdata.dateCl;


Here's where it gets weird- I've been doing my development and debugging with Firefox and the dates displayed are correct. I just loaded the page in Chrome and IE-8 and the dates displayed are "NaN".

Does anyone have a conversion function they can share which works across all browsers? It would be especially great if it also handled the UTC/local time difference. I realized that these routines don't.

Thank you!