The GetYear () method was born earlier and used OK in the early days, but after 2000 years this method has a lot of problems because in browsers like Firefox and Safari, getyear always returns the difference between the year and 1900 years, like returning 98 in 1998, And 2009 will show 109, if everyone is so good, to add together, Microsoft's own in IE browser to the getyear to amend, but Firefox (the latest version does not fix this problem) still in the dark, still honest according to the original rules to resolve getyear, Could have expected the user to amend themselves, so that there is no use, so getFullYear, getUTCFullYear was born.
1, getyear () function
Use the GetYear () method to return a two-bit or four-digit year, and the number returned with getyear () is not necessarily 4-bit! The GetYear () method, which is between 1900 and 1999, returns only two digits. The previous or subsequent years have returned four digits, such as 2009, the JavaScript parser should have returned 2009, while the browser calculates the return of 109. This should be the early agreement, and IE immersed in the change. This function has been deprecated and is not recommended for use.
Copy Code code as follows:
<script type= "Text/javascript" >
var d = new Date ();
document.write (D.getyear ());//ie output 2009,firefox Output 109
</script>
2, Getfullyea () function
The getFullYear function does not have this problem. getFullYear () method can return a four-digit year, so that everyone (ie and Firefox, etc.) do not need to operate, directly to the output of the analytic value.
Copy Code code as follows:
<script type= "Text/javascript" >
var d = new Date ();
document.write (D.getfullyear ());//ie Output 2009,firefox Output 2009
</script>
3, getUTCFullYear () function
The getUTCFullYear () function returns a four-digit number to represent the year based on the UTC time. The getFullYear () method theory is completely different, although the output is the same for most of the time, but if the day date is December 31 or January 1, the return value of getUTCFullYear () and getFullYear () may be different. Depending on the relationship between the local time zone and the UTC universal duration, the difference.
Copy Code code as follows:
<script type= "Text/javascript" >
var d = new Date ();
document.write (D.getutcfullyear ());//ie Output 2009,firefox Output 2009
</script>
For example, in mainland China, Hong Kong, Macao, Mongolia, Taiwan, Singapore, Malaysia, the Philippines and other regions of the local time 8 hours faster than UTC, recorded as Utc+8, meaning is 8 hours faster than UTC time. Subtract a similar understanding, such as UTC-10.