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!