IE and Firefox under the JavaScript getyear year compatibility Writing _ Time and date

Source: Internet
Author: User
Tags time and date
IE and Firefox under JavaScript getyear years different browser JavaScript getyear year function compatibility issues

Let me give you an example.
Some websites on Firefox will see this hint.
It's 106 years, August 8.

and using IE browser will show the normal August 8, 2006

The reason is JavaScript compatibility issues

var today = new Date ();
var year = Today.getyear ();

In Firefox, GetYear returns the value of "Current year-1900" (previously)
And Microsoft has made a change in NB:
When today's year is greater than or equal to 2000, add 1900 to the returned 200X (instead of 10X)
Such as: Today is 1999 return 99
Today's year is 2000 return 2000

JavaScript getyear A simple solution is to add a judgment:
Year = (year<1900? ( 1900+year): Year);

There's another way.
by getFullYear getUTCFullYear to call
var year = Today.getfullyear ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.