Last Updated : Jul 1, 2023
When utilising the system which the user is now using, this function compares the year in accordance with the time zone in effect at the time.
The Date object can be used to display the time and date that are current for that specific user zone and are local time.
This date is given back as the method's return value.
The year of that date is represented by a four-digit value that is returned by the Date.getFullYear() method.
This value was given back as an absolute number.This method doesn't have any parameters.
- We begin our code with HTML tags and the DOCTYPE HTML element. The BODY tag, which has the text alignment set to centre, is then used to begin the code body.
- Next, we used the button tag to construct a button that, when clicked, executes an action and displays the text "click me."
- After that, the script is launched using the H4 heading tag, which holds the id.
- In the script, the function is defined, and thereafter We've made the object Date under this function.
- Using that id and the dateobject, we then print the current year.
- Finally, we use the SCRIPT, BODY, and HTML elements to wrap up our code.
Moreover, we discovered that this technique returns a four-digit absolute number, the year of the date, as the return result.
This number denotes the current year at the provided date and time, which is the one that's represented by the year.