Files
it-know-how/typescript/bits/16-timestamps-with-gettime.md
2026-03-27 12:58:01 +01:00

491 B
Executable File

Timestamps with getTime()

Date.getTime() returns a timestamp in milliseconds since Unix epoch.

Example

const startTime = start.getTime();

Why this is useful

Numeric timestamps are easy to compare:

startTime >= rangeStart
startTime <= rangeEnd

Comparing numbers is usually simpler and safer than comparing date strings directly.

Python comparison

start_ts_ms = int(start_dt.timestamp() * 1000)

Both represent an absolute moment in time.