If you are sure that you are in the right format and donβt need error checking, you can analyze it manually using split (and optionally replace it). I needed to do something similar in my project (MM / DD / YYYY HH: mm: ss: sss) and changed my decision according to your format. Note the subtraction of 1 per month.
var str = "2015-01-16 22:15:00"; //Replace dashes and spaces with : and then split on : var strDate = str.replace(/-/g,":").replace(/ /g,":").split(":"); var aDate = new Date(strDate[0], strDate[1]-1, strDate[2], strDate[3], strDate[4], strDate[5]) ;
Jsub
source share