JS uses new date (str) To create time objects incompatible with Firefox and IE solutions

Source: Internet
Author: User

Or the last time the slide bar problem, suddenly found in Firefox and IE on the scale and time did not show (I developed the use of Google, then did not go to test), so began to add a breakpoint in so many lines of code debugging, finally found new date (strdate), the return is invalid time format, I was depressed ~~~~~ so I went to see the API read the description of the date, in the inside to find other construction methods to try, it is true kung Fu Ah!!!! Finally can be relieved of work!!!! The code is as follows:

/** * Fix IE, Firefox is incompatible with new date (s) * @param strdate * Return Date Object * Add by ZYF at November 5, 2015 */function getdateforstringdate (ST Rdate) {//cutting date and time division is called array var s = strdate.split (""); var S1 = s[0].split ("-"); var s2 = s[1].split (":"), if (s2.length==2) {S2.push ("00");} return new Date (s1[0],s1[1]-1,s1[2],s2[0],s2[1],s2[2]);}



The other constructor is also compatible with the more strong to stick it out

var date = new Date (Strdate.replace ("-", "/"). Replace ("-", "/"));



OK, dinner went to ~~~~~.

JS uses new date (str) To create time objects incompatible with Firefox and IE solutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.