constructor
Date.now
Returns the current time as an integer number of milliseconds since the Unix epoch without allocating a Date object. Use it for timestamps, expiry checks, and simple timing.
Date.now() Parameters
| Parameter | Purpose |
|---|---|
| () | no arguments; returns Number (integer ms) |
| resolution | wall-clock precision (ms); for high-res timing use performance.now() |
Examples
console.log(Date.now()); // e.g. 1784332800000 current epoch milliseconds
const t = Date.now(); doWork(); console.log(Date.now() - t, 'ms'); coarse elapsed timing
console.log(new Date(Date.now()).toISOString()); convert to Date/ISO string
Gotcha
Date.now() is wall-clock and can jump backwards when the system clock is adjusted; use performance.now() for monotonic sub-millisecond timing.
Related
new Date()
Creates a Date object representing a single moment in time as milliseconds since the Unix epoch (1970-01-01T00:00:00Z). Called with no arguments it returns the current instant; with arguments it parses a timestamp, ISO string, or component parts.
Date.prototype.getTime
Returns the underlying timestamp of the date as milliseconds since the Unix epoch (1970-01-01T00:00:00Z). This is the canonical way to compare, subtract, or serialize a Date as a number.
Date.parse
Parses a date string and returns the corresponding milliseconds since the Unix epoch, or NaN if unrecognized. Only the ISO 8601 subset is guaranteed portable; any other format is implementation-defined.
Date.UTC
Returns the milliseconds since the Unix epoch for the given components interpreted as UTC. Unlike the Date component constructor, it does not apply the local timezone.