简体   繁体   中英

Invalid date problems in Internet explorer

This problem is driving me nuts. While my code works fine on Firefox and Google chrome, it is failing on the Internet explorer on Windows 10. But the problem is really weird.

// If I hard code this value, it works fine,
// But the same thing generated by the program fails!
//var dateStr = '2016-08-04 01:38:49'

alert(dateStr)

var a   = dateStr.split(" ");
d       = a[0].split("-");
t       = a[1].split(":");

return new Date(d[0],(d[1]-1),d[2],t[0],t[1],t[2]);

The variable dateStr is filled by my program, and with it the returned date always comes out to be Invalid. However, if I copy the value of dateStr from the alert box, and later hard code the value of dateStr with it, a valid date is returned. What is going on? Am I missing something here? I suspect, this has to do something with unicode strings and stuff. What it could be?

I think the problem is, that your string includes some hidden chars to support eg right-to-left, ..

So your input params to the new Date() cntr are invalid.

Plase notice: if you use dateTime string created by the current system this may cause issues because your parser only supports YYYY-MM-DD hh:mm:ss which is a format based on your system localization and may return a completely different string if your localization is Chinese or Korean

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM