Home > Web Front-end > JS Tutorial > Solution to the problem that the year cannot be displayed normally in Firefox_javascript skills

Solution to the problem that the year cannot be displayed normally in Firefox_javascript skills

WBOY
Release: 2016-05-16 16:37:17
Original
1283 people have browsed it

We will see this display on some websites when using Firefox:
The current time is: January 26, 108

The IE browser displays normally:
The current time is: January 26, 2008

The reason is the compatibility issue of javascript

var today = new date();var year = today.getYear();
Copy after login

In Firefox, getYear returns the value of "current year-1900", but Microsoft has made a change:
When the year of today is greater than or equal to 2000, 1900 is added directly and the returned 200X (instead of 10X)
For example: today’s year is 1999, return 99
Today’s year is 2000. Return 2000

A simple solution is to add a judgment:

year = (year<1900&#63;(1900+year):year);
Copy after login

There is also another method:
Call
through getFullYear getUTCFullYear

var year = today.getFullYear();
Copy after login
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