


How to solve the problem that the Safari browser of JS IOS/iPhone is not compatible with Date() in Javascript
var date = new Date('2016-12-6 11:11:11'); document.write(date);
Recently I am writing a time judgment script, which needs to convert the fixed string time into a timestamp for comparison. When doing this, I am used to using chrome as a debugging tool. After the code is basically completed, everything is normal;
Use other browsers Well, IE and Safari are not compatible and return the error "Invalid Date".
I thought it might be a problem with the string format, so I changed it to '2016/11/11 11:11:11' and tested again. The result was normal. I thought this should be no problem. Then I used the mobile browser to continue accessing. Android is normal. The iPhone continued to report an error.
Then I changed "Nov 11 2016 11:11:11" and it still reported an error. No matter how I changed it, it didn't work. After racking my brains, I finally 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 compatible with all browsers, conclusion:
Safari in iPhone cannot interpret time formats such as YYYY-MM-DD HH:mm:ss or YYYY/MM/DD HH:mm:ss, while Google Firefox, etc. The browser has extended such a format. The formats supported by
Safari on the iPhone are YYYY, MM, DD, HH, mm, ss. This problem has bothered me for most of the day. I really want to attract Apple programmers. Going out and shooting people for 10 minutes is so fucking unique. Annoying

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor
