JavaScript getFullYear 函数是 Date 函数之一,它返回给定日期的完整年份。我们使用 getFullYear 来从当前日期和时间返回年份 (yyyy)。
<!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
在这个 get Full Year 函数示例中,我们从自定义日期中提取完整年份。
<!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>

在此示例中,我们从不包含年份的自定义日期中提取年份。此 JavaScript get Full 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