Home >Web Front-end >JS Tutorial >Sharing the similarities and differences of Javascript's getYear, getFullYear, and getUTCFullYear_javascript skills
Among them, the getYear() method was born earlier, and OK has been used in the early days. However, this method has many problems after 2000, because on browsers such as Firefox and Safari, getYear always returns the difference between the year and 1900, such as 1998 The year returns 98, while 2009 will display 109. If everyone does it this way, they have to add it all up. Microsoft itself has corrected getYear in IE, but Firefox (the latest version has not corrected this problem) still has They were kept in the dark and still parsed getYear according to the original rules. They could have expected users to correct it themselves, but it was useless, so getFullYear and getUTCFullYear were born.
1. getYear() function
Use the getYear() method to return a two-digit or four-digit year. The number returned by getYear() is not necessarily It’s 4 digits! The getYear() method between 1900 and 1999 returns only two digits. Years before or after are returned as four-digit numbers. For example, in 2009, the Javascript parser should return 2009, while the browser calculates and returns 109. This should be an early agreement, but IE changed it. This function has been gradually deprecated and is not recommended.