Below is the example of Date getFullYear() method.
// Here a date has been assigned
// while creating Date object
'October 15, 1996 05:35:32'
// year from above date object is
// being fetched using getFullYear().
B = dateobj.getFullYear();
// Printing year
The date.getFullYear() method is used to fetch the year from a given Date object.
Parameter: This function does not accept any parameters.
Return Values: It returns the year for the given date.
More codes for the above method are as follows:
Program 1: If nothing as parameter is given to the Date() constructor, then the getFullYear() function returns current year.
Program 2: The date of the month must lie between 1 to 31 because a month cannot have more than 31 days. That is why it returns NaN i.e, not a number because the date for the month does not exist. Hence, Year will not exist when the date of the month is set as 45 or any number which does not lie between 1 to 31.
Program 3: It has applications such as getting current year.It is used in websites to validate the age of the user.
- Google Chrome
- Internet Explorer