I have this date as string with me 15-07-2011 which is in the format dd-mm-yyyy. I needed to create a Date object from this string. So I have to convert the date in dd-mm-yyyy to mm-dd-yyyy format.
What I did is the following.
var myDate = '15-07-2011';
var chunks = myDate.split('-');
var formattedDate = chunks[1]+'-'+chunks[0]+'-'+chunks[2];
Now I got the string 07-15-2011 which is in mm-dd-yyyy format, and I can pass it to the Date() constructor to create a Date object. I wish to know if there is any cleaner way to do this.
That looks very clean as it is.