setYear

Commons
stable

Return a new Date with the full year replaced by the given value. The original date is never mutated.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

date
requis
Date
The source date. It is cloned before the year is updated.
year
requis
number
The four-digit year to set (e.g. 2025).

API

Valeur de retour

La valeur retournée par cet util.

A new Date object with the specified year.

Usage

Exemples

Extraits de code prêts à coller.

Change the year of a date

typescript