addMonths

Date
stable

Return a new Date shifted by the given number of months. To avoid day-overflow issues (e.g. Jan 31 + 1 month), the day-of-month is reset to 1 before advancing the month. The original date is never mutated.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

addMonths resets the day to 1 before offsetting the month to avoid overflow (e.g. 31 Jan + 1 month becoming 2 or 3 March). This differs from simple setMonth arithmetic.

API

Paramètres

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

date
requis
Date
The base date. Not mutated.
amount
requis
number
Number of months to add. Negative values subtract months.

API

Valeur de retour

La valeur retournée par cet util.

A new Date instance at the 1st day of the target month.

Usage

Exemples

Extraits de code prêts à coller.

Advance a calendar month

typescript