Date.parse() doesn't work in IE 8

后端 未结 3 1090
無奈伤痛
無奈伤痛 2021-01-14 19:15

Simple function Date.parse() not working well in Internet Explorer 8.
I am using Date.parse() to validate date in format

3条回答
  •  有刺的猬
    2021-01-14 19:36

    Standard JavaScript only accepts RFC 2822 dates, which don't look like that. You'll have to write your own code to separate out the date parts, convert them to numbers, and make Date instances that way.

    Internet Explorer also supports ISO dates (2012-09-20 08:22), and it will in fact parse "MM/DD/YYYY" dates. It's doing that for your "13/35/2012" date, which as far as JavaScript is concerned is a perfectly valid date: it's 04 February 2013. JavaScript "fixes" bogus dates; the 13th month of the year is the first month of the following year, and the 35th day of the month (if it's January, with 31 days) is the fourth day of the next month.

    Basically you're expecting the Date parser to behave differently than it actually does.

提交回复
热议问题