setMonth

Commons
stable

Return a new Date with the month replaced by the given zero-based index (0 = January). The original date is never mutated.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

date
required
Date
The source date. It is cloned before the month is updated.
count
required
number
Zero-based month index (0 = January … 11 = December). Values outside 0–11 roll over into adjacent years.

API

Return value

The value returned by this util.

A new Date object with the specified month.

Usage

Examples

Ready-to-paste usage snippets.

Switch to a different month

typescript