Home > Web Front-end > JS Tutorial > 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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:07:08
Original
1207 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:
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
Latest Issues
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template