Js IE does not support the new date () method solution

Source: Internet
Author: User

This article introduces how to solve js new date () function not supported in IE browser. For more information, see.

Solution 1

The Code is as follows: Copy code

Function NewDate (str ){
If (str = null)
Return false;
Str = str. split ('-');
Var date = new Date ();
Date. setUTCFullYear (str [0], str [1]-1, str [2]);
Date. setUTCHours (0, 0, 0, 0 );
Return date;
}

Solution 2

 

The Code is as follows: Copy code
Function getDays (strDateStart, strDateEnd ){
Var strSeparator = "-"; // Date Separator
Var oDate1;
Var oDate2;
Var iDays;
ODate1 = strDateStart. split (strSeparator );
ODate2 = strDateEnd. split (strSeparator );
Var strDateS = new Date (oDate1 [0], oDate1 [1]-1, oDate1 [2]);
Var strDateE = new Date (oDate2 [0], oDate2 [1]-1, oDate2 [2]);
IDays = parseInt (Math. abs (strDateS-strDateE)/1000/60/60/24) // converts the number of milliseconds to the number of days
Return iDays;
}

Related Article

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.