Date

Date.prototype.setFullYear

Sets the full year for a specified date according to local time and returns the updated timestamp

Syntax

JavaScript
date.setFullYear(yearValue, monthValue?, dateValue?)

Parameters

ParameterTypeDescription
yearValuenumberThe full year
monthValuenumberOptional month (0-11)
dateValuenumberOptional day of month (1-31)

Return Value

The number of milliseconds from epoch for the updated date

Examples

Basic Usage
const date = new Date();
date.setFullYear(2025);
console.log(date.getFullYear()); // 2025
Practical Example
const date = new Date('2024-06-15');
date.setFullYear(2024, 0, 1); // Jan 1, 2024
console.log(date.toISOString());
Advanced Usage
function addYears(date: Date, years: number) {
  const d = new Date(date);
  d.setFullYear(d.getFullYear() + years);
  return d;
}

Understanding Date.prototype.setFullYear

The Date.prototype.setFullYear method in JavaScript sets the full year for a specified date according to local time and returns the updated timestamp. It belongs to the Date object and is one of the most widely used methods for working with date values in modern JavaScript and TypeScript applications.

The method signature is date.setFullYear(yearValue, monthValue?, dateValue?). It accepts 3 parameters: yearValue, monthValue, dateValue. When called, it returns the number of milliseconds from epoch for the updated date. Understanding when and how to use setFullYear() helps you write more expressive, readable code.

Common use cases for Date.prototype.setFullYear include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like date-getfullyear, date-setmonth, date-setdate, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Date.prototype.setFullYear is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Date Methods

Other methods in the Date object

Related Tools

More Date Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.