New Date () ISO does not support compatibility issues

Source: Internet
Author: User

The Safari browser in IOS5 and above (not including IOS5) correctly interprets the date object of the new date (' 2013-10-21 ') in JavaScript.     However, the IOS5 version of Safari explains that new date (' 2013-10-21 ') is not correct, and the return in IOS5 Safari is always "Invalid date". Later I found the information on the Internet, originally the low version of Safari explained that the new date (' 2013-10-21 ') This object is not the same, in IOS5 Safari does not support this type of writing, and it supports the wording of the new date (' 2013 ', ' 10 ', ' 21 ')     , this will solve the "Invalid date" problem and return a JavaScript date back. But then the problem arose, and date returned, but the data returned by the method in the Date object was not what I wanted, and the returned data were all incorrect.     Specific is what reason I also not too clear, also please know the principle of the prawn to guide! Now return to the Date object. GetMonth () One months more than normal! and. GetDay () The day of the week returned is also incorrect!     ╮(╯▽╰)╭ annoyed Ah, torture ah .... I began to scold the development of the safari of these people, but scold to scold the problem or to solve, or wages on the wood has!     Oh! Then I checked a lot of foreign technical blog, finally found a solution, originally wanted to IOS5 in the safari can correctly parse the new Date () so it must be written new Date (' 2013/10/21 '); or

var d = new Date (date);
D = d.getfullyear () > 0? D:new Date (Date.parse (Date.replace (/-/g, "/")));

Write yourself a piece of code

This.state.clearTime = SetInterval (() =>{

Let date = new Date ();

This.props.desk_start_time from backstage ' 201612231933 ' turn him into 2016/12/23 19:33
       Let Datet = This.props.desk_start_time.replace (/(\d{4}) (\d{2}) (\d{2}) (\d{2}) (\d{2})/, "$1/$2/$3 $4:$5");
In milliseconds, so you want to divide 1000
Let DateTime = (date-new date (datet))/1000;

}). 1000}

New Date () ISO does not support compatibility issues

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.