The new date function of JavaScript The pit _javascript techniques encountered in Safari

Source: Internet
Author: User

Recently, when I was doing mobile web, I was successful with chrome debugging on my PC, but there were strange problems with the real machine on the iphone. After a series of debugging found that the date is related to the problem. It was initially suspected to be a production environment problem, but the same problem has arisen with the Mac version of Safari debugging locally. Looking at some of the data, it turns out that Safari's support for the new date function for JavaScript has a rather bizarre problem.

Typically, the date is formatted as a YYYY-MM-DD because it is accustomed to the DateTime format in SQL, but Safari does not support such a format, so when you enter the following statement, it returns an empty time.

New Date (' 2016-04-17 ');

Safari support Format is YYYY/MM/DD, the difference is mainly in the short horizontal-and slash/, and slashes such a format in other common browsers can also be normal operation, so only need to be replaced by a slash, the conversion function is as follows:

New Date (' 2016-04-17 '. Replace (/-/g, "/"));

The above is a small set up to introduce the JavaScript new date functions in Safari encountered in the pit, hope for everyone to help, 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!

Related Article

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.