The year cannot be displayed properly in Firefox
- 2020-03-30 03:54:47
- OfStack
Some of the sites we see on Firefox look like this:
The time is now: January 26, 108
Internet explorer, on the other hand, displays normal:
The time is now: January 26, 2008
The reason is the compatibility problem of javascript pt
var today = new date();var year = today.getYear();
In Firefox getYear returns the value of "current year - 1900", and Microsoft has made a change:
When the year of today is greater than or equal to 2000 we just added 1900 to the return of 200X.
The year today was 1999 and 99 was returned
The year today is 2000 and returns 2000
A simple solution is to add a judgment:
year = (year<1900?(1900+year):year);
There are other ways:
Call getFullYear getUTCFullYear
var year = today.getFullYear();