Change date format in javascript
<p>I have an example which finds the difference of days between 2 specified dates and works only in Chrome, I think in firefox 6 and IE8 it does not support the format of date that I am using (shows <code>NaN</code>). Can somebody help me change the format to desired 1 (see below)?</p>

<p>Here is my <a href="http://jsfiddle.net/vQnHz/5/" rel="nofollow">DEMO</a></p>

<p><strong>My format</strong> : <code>2011-08-18 11:49:01</code></p>

<p><strong>Desired format</strong> : <code>08-18-2011 11:49:01</code></p>

<p>My Code</p>

<pre><code>var cellvalue="2011-08-18 11:49:01.0 IST";
var firstDate = new Date();
var secondDate = cellvalue.substring(0, cellvalue.length-4);
alert(diffOf2Dates(firstDate,secondDate));
function diffOf2Dates(todaysDate,configDate)
{
/*var udate="2011-08-18 11:49:01.0";
var configDate=new Date(udate);*/

var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = todaysDate; // Todays date
var secondDate = new Date(configDate);

var diffDays = Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));


return Math.ceil(diffDays);
}
</code></pre>
