JS Ios/iphone in Safari incompatible with date () issues in JavaScript

Source: Internet
Author: User
Tags string format

1 var New Date (' 2016-11-11 11:11:11 '); 2 document.write (date);

Recently write a time to judge the script, you need to convert the fixed string time to a timestamp to compare, when doing the personal habit of using chrome as a debugging tool,

After the code is basically complete, everything is OK;

Use other browsers to access, well, IE is incompatible with Safari and returns the error "Invalid Date".

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

Change "11 2016 11:11:11", still error, how to change

Racked his brains, and finally saw a solution on the forum:

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

Can finally be compatible with all browsers, conclusion:

Safari in the iphone can't explain the time format of Yyyy-mm-dd HH:mm:ss or Yyyy/mm/dd HH:mm:ss, and Google Firefox and other browsers have extended this format.

The iphone in the format supported by the Safari yyyy,mm, DD,HH,MM,SS, this problem tangled me for half a day, really want to pull out the Apple programmer to shoot 10 minutes, too TM Maverick. Irritating

JS Ios/iphone in Safari incompatible with date () issues in JavaScript

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.