I have this date as a line with me 07/15/2011, which is in the format dd-mm-yyyy. I needed to create an object Datefrom this line. So I need to convert the date in format dd-mm-yyyyto mm-dd-yyyy.
I did the following.
var myDate = '15-07-2011';
var chunks = myDate.split('-');
var formattedDate = chunks[1]+'-'+chunks[0]+'-'+chunks[2];
Now I got the line 07-15-2011, which is in the format mm-dd-yyyy, and I can pass it to the constructor Date()to create the object Date. I want to know if there is a cleaner way to do this.
source
share