JavaScript Date Object
Definition and usage
The getFullYear () method returns a 4-digit number that represents the year.
Grammar
Dateobject.getfullyear ()
return value
The year that is returned when Dateobject is represented in local time. The return value is a four-digit number that represents the full year, including the century value, rather than the abbreviated form of a two-digit number.
Tips and Comments:
Note: This method is always used in conjunction with a Date object.
Example 1
In this example, we will get the current year and output it:
<script type= "Text/javascript" >var d = new Date () document.write (D.getfullyear ()) </script>
Output:
2017
Example 2
In this example, we will extract the year from the specific date:
<script type= "Text/javascript" >var born = new Date ("July, 1983 01:15:00") document.write ("I was born in" + BORN.G Etfullyear ()) </script>
Output:
I was born in 1983
Tiy
-
Display the current date in a different format
-
How to use GetDate (), GetMonth (), and getFullYear () to display the current date in a different format.
JavaScript Date Object
JavaScript getFullYear () method