google chrome - JavaScript Date not working properly in IE8 -
this question has answer here:
chrome showing result expected ie-8 giving nan when execute following:
chrome:
d = new date("2014 12 01") // results mon dec 01 2014 00:00:00 gmt+0500 (pakistan standard time)
ie-8:
d = new date("2014 12 01") // results nan undefined
the format you're trying parse doesn't match the specific format new date
required parse. parse reliably cross-browser, need parse explicitly — either in own code, can trivially done regex, or using library momentjs , telling format is.
the trivial regex solution:
// note! uses local time. var yourstring = "2014 12 01"; var parts = yourstring.match(/^(\d{4}) (\d{2}) (\d{2})$/); if (parts) { var date = new date(+parts[1], +parts[2] - 1, +parts[3]); alert(date.tostring()); }
Comments
Post a Comment