Home > Web Front-end > JS Tutorial > Handling of compatibility issues of Date() function in browsers

Handling of compatibility issues of Date() function in browsers

php中世界最好的语言
Release: 2018-04-17 11:46:03
Original
1648 people have browsed it

This time I will bring you Date()FunctionHandling of compatibility issues in the browser, Date() function handling of compatibility issues in the browserNotesWhat are the actual cases? Let’s take a look at them.

Generally, direct new Date() will not cause compatibility problems, but new Date(datetimeformatstring) often causes browser compatibility problems. Why, some of the datetimeformatstring The format browser is not compatible.

1. No parameters

//无参 所有浏览器都兼容
var dateTime = new Date();
Copy after login

2.Date parameter

//日期参数 格式1
var dateTime = new Date("2017-09-12");
Copy after login

a. IE

  > IE9- (not compatible)  

IE9 (compatible, including IE9)

b. Firefox (compatible)

c. Google (compatible)

//日期参数 格式2 所有浏览器都兼容
var dateTime = new Date("2017/09/12");
Copy after login

3. Date and time parameters

//日期时间参数 格式1
var dateTime = new Date("2017-09-12 13:41:00");
Copy after login

a. IE (not compatible, no matter which version)

b. Firefox (not compatible)

c. Google (compatible)

//日期时间参数 格式2 所有浏览器都兼容
var dateTime = new Date("2017/09/12 13:42:00");
Copy after login
//日期时间参数 格式3
var dateTime = new Date("2017-09-12T13:42:00");
Copy after login

a. IE

  > IE9- (not compatible)

  > IE9 (compatible)

  > IE9 (semi-compatible 8 hours time difference)

b. Firefox (compatible)

c. Google (semi-compatible 8 hours time difference)

//日期时间参数 格式4
var dateTime = new Date("2017/09/12T13:42:00");
Copy after login

a. IE (semi-compatible 1 hour time difference)

b. Firefox (not compatible)

c. Google (not compatible)

To sum up, the format supported by all major browsers is: var dateTime = new Date("2017/09/12 13:42:00");

Then the solution is to convert datetimeformatstring into yyyy/MM/dd hh:mm:ss Format stringThat’s it

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:



The above is the detailed content of Handling of compatibility issues of Date() function in browsers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template