Firefox's getyear Considerations _javascript Tips

Source: Internet
Author: User
Last week in the collation of a previously written calendar script, FF under the annual display is always a problem, make a depressed s. For example, the following script: under IE hint "2007"-No Problem! But under the FF is prompted "107"?
<script> var today = new Date (); Alert (Today.getyear ()); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Google a bit, just understand in the FF getyear return is "Current year-1900" value (Legend has been this way before), and NB of Ms but when the year>=2000, directly minus 1900 added back. Hehe, again admire IE's fault tolerant ability and magnanimous ^_^

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

Of course you have to judge browser type classification processing is also no problem.

The most reasonable is to use the getyear getFullYear or getutcfullyear to call, you can change the code box above to see the results.

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.