toDate

Calendar
stable

Coerce a Date, ISO string, or epoch number to a Date instance. Returns null for null, undefined, and unparseable values so the caller can branch without catching exceptions.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

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

value
requis
Date | string | number | null | undefined
The raw value to coerce. A Date is cloned; a string is parsed via `new Date()` (ISO-8601 natively supported); a number is treated as epoch milliseconds. null and undefined return null immediately.

API

Valeur de retour

La valeur retournée par cet util.

A new Date instance on success, or null when the input is null/undefined/unparseable (NaN check applied).

Usage

Exemples

Extraits de code prêts à coller.

Coercing various input types

typescript