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