JavaScript's getyear, getFullYear, getutcfullyear and similarities and differences share _javascript skills

Source: Internet
Author: User
Tags local time
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.
Related Article

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.