setYear
Commons
stable
Return a new Date with the full year replaced by the given value. The original date is never mutated.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- daterequiredDate
- The source date. It is cloned before the year is updated.
- yearrequirednumber
- The four-digit year to set (e.g. 2025).
API
Return value
The value returned by this util.
- A new Date object with the specified year.
Usage
Examples
Ready-to-paste usage snippets.
Change the year of a date