Home  >  Article  >  Web Front-end  >  Compatibility of writing javascript getyear year under IE and Firefox_time and date

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

WBOY
WBOYOriginal
2016-05-16 19:07:081115browse

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();

Statement:
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