JS Ios/iphone's Safari browser is not compatible with the date () problem in JavaScript How to solve _javascript skills

Source: Internet
Author: User
Tags string format
var date = new Date (' 2016-11-11 11:11:11 ');
document.write (date);

Recently in writing a time to judge a script, you need to convert the fixed string time to the timestamp for comparison, in doing the personal habit of using chrome as a debugging tool, after the basic code is complete, all normal;

Access with other browsers, well, IE is not compatible with Safari, returning the error "Invalid Date."

Think of the problem is a string format, changed to ' 2016/11/11 11:11:11 ' again test, the result is normal, think this should be no problem, and then continue to access the mobile phone browser, Android Normal, the iphone continues to complain,

Then change "Nov 11 2016 11:11:11", the same error, how to change all not

Racking my brains, I finally saw this 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] C4/>document.write (date);

Finally can be compatible with all browsers, the conclusion:

Safari in the iphone can't explain time formats like Yyyy-mm-dd HH:mm:ss or Yyyy/mm/dd HH:mm:ss, and browsers such as Google Firefox have extended the format

Safari in the iphone format supported by YYYY,MM, DD,HH,MM,SS, this problem tangled me for a long time, really good want to pull out the Apple programmer to shoot 10 minutes, too TM Maverick. Irritating

The above is a small set to introduce the JS Ios/iphone safari incompatible JavaScript date () problem solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.