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
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- valuerequiredDate | 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
Return value
The value returned by this util.
- A new Date instance on success, or null when the input is null/undefined/unparseable (NaN check applied).
Usage
Examples
Ready-to-paste usage snippets.
Coercing various input types