myowin76
7/12/2013 - 4:32 PM

jquery convert date string to Date Object

jquery convert date string to Date Object

// method which parses a date string in the format YYYY-MM-DD and creates a Date object
function parseDate(dateString) {
     // split the string get each field
     var dateArray = dateString.split("-");
     // now lets create a new Date instance, using year, month and day as parameters
     // month count starts with 0, so we have to convert the month number
     var date = new Date(Number(dateArray[0]), Number(dateArray[1]) - 1, Number(dateArray[2]));
     return date;
}