JavaScript getFullYear Function

JavaScript getFullYear function is one of the Date Functions, which returns the full year from a given. We are using the getFullYear to return the year (yyyy) from the current date and time.

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt);
  document.write("Full Year : " + dt.getFullYear());
</script>
</body>
</html>
Example

Date and Time: Sat Nov 03 2018 18:04:36 GMT+0530 (Indian Standard Time)
Full Year : 2018

getFullYear Example

In this get Full Year Function example, we extract the full year from the custom date.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScriptGetFullYearFunction </title>
</head>
<body>
    <h1> JavaScriptgetFullYearFunctionExample </h1>
<script>
  var dt = Date("April 29, 2012 10:09:07");
  document.write("Date and Time : " + dt);
  document.write("Full Year from getFullYear(): " + dt.getFullYear());
</script>
</body>
</html>
getFullYear Example

We extract the year from the custom date without a year in this example. This JavaScript get Full Year Function example will return the default year.

<!DOCTYPE html>
<html>
<head>
    <title> JS</title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date("June 29 10:09:07");
  document.write("Date and Time : " + dt);
  document.write("Full Year : " + dt.getFullYear());
</script>
</body>
</html>
Example

Date and Time: Fri Jun 29 2001 10:09:07 GMT+0530 (Indian Standard Time)
Full Year : 2001