JavaScript getFullYear Function

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

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

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

JavaScript getFullYear Function Example

In this JavaScript get Full Year Function example, we are extracting the full year from the custom date

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Get Full Year Function </title>
</head>
<body>
    <h1> JavaScript getFullYear Function Example </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>
JavaScript getFullYear Function 2

In this get Full Year example, we extract the year from the custom date without a year. This JavaScript getFullYear Function example will return the default year.

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

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