Precautions for getYear of FireFox

Source: Internet
Author: User

Last week, I was sorting out a calendar script that I wrote previously. FF always had problems with the display of the year, and I was so depressed. For example, the following script prompts "2007" under IE -- No problem! But does FF prompt "107 "?
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

After a Google query, we can see that the value of "current Year-1900" is returned in FF's getYear (which is said to have been handled in the past), while NB's MS is regarded as Year> = 2000, add the subtract 1900 again. Haha, I once again admire the fault tolerance capability and belly capacity of IE ^_^

The most direct solution is year = (year <1900 )? (1900 + year): year;

Of course, you have to judge the Browser type and then classify it.

The most reasonable thing is to call getYear with getFullYear or getUTCFullYear. You can change the corresponding Code in the Code box above to see the effect.

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.