Date.getFullYear() function in JavaScript


The Date object is a data type built into the JavaScript language. Date objects are created with the new Date( ) as shown below.

Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.

The getFullYear() function of the Date object returns the year in the specified date.The value returned by getFullYear() is an absolute number. For dates between the years 1000 and 9999, getFullYear() returns a four-digit number, for example, 2008.

Syntax

Its syntax is as follows

dateObj.getFullYear();

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var dateObj = new Date('september 26, 89 00:4:00');
      document.write(dateObj.getFullYear());
   </script>
</body>
</html>

Output

1989

Example

Incase if you have created a date object without passing any value to its constructor this function returns the current year value.

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var dateObj = new Date();
      document.write(dateObj.getFullYear());
   </script>
</body>
</html>

Output

2018

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 25-Jun-2020

239 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements