Home > Web Front-end > JS Tutorial > body text

Compatibility of writing javascript getyear year under IE and Firefox_time and date

WBOY
Release: 2016-05-16 19:07:08
Original
1142 people have browsed it

Compatibility issues of JavaScript getyear year function between IE and Firefox in different browsers

Let’s give an example first
You will see such a prompt when using Firefox on some websites
The current time is 106 years August 8th

If you use IE browser, it will display normally August 8th, 2006

The reason is the compatibility issue of javascript

var today = new date ();
var year = today.getYear();

In Firefox, getYear returns the value of "current year-1900" (this was the case before)
And Microsoft is very NB. Made a change:
When today's year is greater than or equal to 2000, 1900 is added directly to the returned 200X (instead of 10X)
For example: today's year is 1999, 99 is returned
Today's year is 2000, 2000 is returned

A simple solution to javascript getyear is to add a judgment:
year = (year
There is also another method
through getFullYear getUTCFullYear to call
var year = today.getFullYear();

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