toSeconds
Converts a date to a timestamp in seconds (epoch seconds).
Use this when sending a date to a backend API that expects seconds
(e.g. Java Instant.getEpochSecond(), Python time.time()).
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
date | DateLike | The date to convert |
Returns
Section titled “Returns”number | null — Seconds since the Unix epoch, or null for invalid input
Examples
Section titled “Examples”toSeconds
Section titled “toSeconds”Related Types
Section titled “Related Types”DateLike
Section titled “DateLike”A value that can be converted to a Date.
Date— used as-is (validated for Invalid Date)number— treated as a timestamp (seconds or milliseconds, auto-detected);0is treated as invalid and producesnullin ensureDatestring— parsed vianew Date(string)Temporal.Instant|Temporal.ZonedDateTime— read via theirepochMillisecondsproperty
