Js ios/iPhone Safari is not compatible with Date () in Javascript. How can this problem be solved?

Source: Internet
Author: User

Js ios/iPhone Safari is not compatible with Date () in Javascript. How can this problem be solved?

Var date = new Date ('2017-11-11 11:11:11 '); document. write (date );

Recently, when writing a time judgment script, you need to convert a fixed string time to a timestamp for comparison. When doing this, I am used to using chrome as a debugging tool. After the code is basically complete, everything is normal;

If you use other browsers for access, IE and safari are incompatible, and the error "Invalid Date" is returned ".

I thought it would be a string format problem. I changed it to '2017/11 11:11:11 'and then tested it. The result was normal. I thought it would be okay. I used a mobile browser to continue accessing it. android is normal, the iPhone continues to report an error,

If you change "Nov 11 2016 11:11:11", the system will report an error.

Finally, I saw such a solution on the Forum:

Var arr = "2016/11/11 11:11:11 ". split (/[-: \/]/), date = new Date (arr [0], arr [1]-1, arr [2], arr [3], arr [4], arr [5]); document. write (date );

Finally, it is compatible with all browsers. Conclusion:

IPhone safari could not explain YYYY-MM-DD HH: mm: ss or YYYY/MM/dd hh: mm: ss such a time format, and Google Firefox and other browsers on such a format extended,

The formats supported by safari in iPhone are YYYY, MM, DD, HH, mm, and ss. This problem has plagued me for a long time. I really want to take apple programmers out for 10 minutes, TTM is a maverick. Irritating

The preceding section describes how to solve the Date () Problem in Javascript IOS/iPhone Safari that is incompatible with Javascript, if you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!

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.