Why getyear () cannot get the correct year

Source: Internet
Author: User

Why getyear () cannot get the correct year:
In some JS code, especially the old JS code, there may be no way to get the correct year phenomenon, first look at a code example:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.51texiao.cn/" /><title>Ant Tribe</title><Scripttype= "Text/javascript">window.onload=function(){   varParent=document.getElementById ("Parent"); varmydate=NewDate (); Parent.innerhtml=mydate.getyear ();} </Script> </Head> <Body> <DivID= "Parent"></Div> </Body> </HTML>

The above code in FF, Firefox, IE9 or IE9 above the browser, do not get the year correctly, such as the current year is 2013, but the getyear () return value is 113, and in IE8 or IE8 below the browser can get the correct year 2013, This does not explain why this happens because it is now recommended to use the getFullYear () function instead of the getyear () function, since this function can be compatible with all major browsers and the code is modified as follows:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.51texiao.cn/" /><title>Ant Tribe</title><Scripttype= "Text/javascript">window.onload=function(){   varParent=document.getElementById ("Parent"); varmydate=NewDate (); Parent.innerhtml=mydate.getfullyear ();} </Script> </Head> <Body> <DivID= "Parent"></Div> </Body> </HTML>

The original address is http://www.51texiao.cn/javascriptjiaocheng/2015/0405/120.html

Why getyear () cannot get the correct year

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.