


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
