JS date () Day function Browser compatibility problem solving method

Source: Internet
Author: User

The General direct new Date () is not a compatibility issue, and the new date (datetimeformatstring) often has browser compatibility issues, why some format browsers in datetimeformatstring are incompatible.

1. No reference

12 //无参 所有浏览器都兼容vardateTime = newDate();

2. Date parameters

12 //日期参数 格式1vardateTime = newDate("2017-09-12");

A. IE

> ie9-(Incompatible)

> ie9+ (compatible, including IE9)

B. Firefox (compatible)

C. Google (compatible)

12 //日期参数 格式2 所有浏览器都兼容vardateTime = newDate("2017/09/12");

3. Date and Time parameters

12 //日期时间参数 格式1vardateTime = newDate("2017-09-12 13:41:00");

A. IE (incompatible, no matter which version)

B. Firefox (not compatible)

C. Google (compatible)

12 //日期时间参数 格式2 所有浏览器都兼容vardateTime = newDate("2017/09/12 13:42:00");
12 //日期时间参数 格式3vardateTime = newDate("2017-09-12T13:42:00");

A. IE

> ie9-(Incompatible)

> ie9+ (Compatible)

> IE9 (Semi-compatible 8-hour time difference)

B. Firefox (compatible)

C. Google (half-compatible 8-hour time difference)

12 //日期时间参数 格式4vardateTime = newDate("2017/09/12T13:42:00");

A. IE (half-compatible 1-hour time difference)

B. Firefox (not compatible)

C. Google (not compatible)

In all, the formats supported by all major browsers are: var dateTime = new Date ("2017/09/12 13:42:00");

So the solution is to convert datetimeformatstring to YYYY/MM/DD HH:MM:SS formatted string

JS date () Day function Browser compatibility problem solving method

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.