Ie9 +, use date ("2013-01-01") for string to date in chrome Firefox opera; all are OK.
However, in IE7 and IE8, Nan is returned.
Someone abroad has written such a solution.
/** Parses string formatted as YYYY-MM-DD to a date object. * If the supplied string does not match the format, an * invalid date (value Nan) is returned. * @ Param {string} datestringinrange format YYYY-MM-DD, with year in * range of 0000-9999, inclusive. * @ return {date} date object representing the string. */function parseiso8601 (datestringinrange) {var isoexp =/^ \ s * (\ D {4})-(\ D) \ s * $ /, Date = new date (NAN), month, parts = isoexp.exe C (datestringinrange); If (parts) {month = + parts [2]; date. setfullyear (parts [1], month-1, parts [3]); If (month! = Date. getmonth () + 1) {date. settime (NAN) ;}} return date ;}
Use:
Parseiso8601 ("2013-01-01 ");