JS code Browser compatibility new Date ()

Source: Internet
Author: User

Only 3 browsers are tested here: IE, Firefox, Google.

I. Non-reference

// No reference var New Date ();

All browsers are compatible, good

Two. Date parameters

// Date parameter Format 1 var New Date ("2016-05-20");

A. IE

> ie9-(Incompatible)

> ie9+ (compatible, including IE9)

B. Firefox (compatible)

C. Google (compatible)

// Date parameter Format 2 var New Date ("2016/05/20");

All browsers are compatible, good

Three. Date and time parameters

// Date Time parameter format 1 var New Date ("2016-05-20 23:41:00");

A. IE (incompatible, no matter which version)

B. Firefox (not compatible)

C. Google (compatible)

// Date Time parameter format 2 var New Date ("2016/05/20 23:42:00");

All browsers are compatible, good

// Date Time parameter Format 3 var New Date ("2016-05-20t23:42:00");

A. IE

> ie9-(Incompatible)

> ie9+ (Compatible)

> IE9 (semi-compatible)

What's a half-compatible? Ha ha. Semi-compatibility is the time to get a date, but the time is wrong. For example, our time is 23:42:00. Then it will automatically add 8 hours on this basis, so the value we get for DateTime will be: 2016-05-21 07:42:00

B. Firefox (compatible)

C. Google (semi-compliant) with IE9 time increased by 8 hours

// Date Time parameter format 4 var New Date ("2016/05/20t23:42:00");

A. IE (semi-compatible) all versions have been added for 1 hours, that is, the resulting dateTime value is: 2016-05-21 00:42:00

B. Firefox (not compatible)

C. Google (not compatible)

based on the results of the above tests, the formats supported by all browsers are: var dateTime = new Date ("2016/05/20 23:42:00");

JS code Browser compatibility new Date ()

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.