Skip to main content

now()

now(): number

Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.

DEPRECATED

Use Date.now() directly instead.


Returns: numberโ€‹

The current Unix timestamp in milliseconds.


See Alsoโ€‹


Sinceโ€‹

2.0.0


Also known asโ€‹

now (Lodash) ยท timestamp (Antfu) ยท โŒ (es-toolkit, Remeda, Radashi, Ramda, Effect, Modern Dash)


Exampleโ€‹

// โŒ Deprecated approach
const timestamp = now();

// โœ… Recommended approach
const timestamp = Date.now();

How it works?โ€‹

Gets the timestamp of current time. Deprecated: Use Date.now() directly (ES5).

Native Equivalentโ€‹

// โŒ now()
// โœ… Date.now()

Use Casesโ€‹

Get current timestamp ๐Ÿ“Œโ€‹

Get the current Unix timestamp in milliseconds.

Date.now();
// => 1705708800000

Measure elapsed timeโ€‹

Calculate time between operations.

const start = Date.now();
// ... operation ...
const elapsed = Date.now() - start;

Generate unique IDsโ€‹

Use timestamp for unique identifiers.

const id = `item_${Date.now()}`;
// => "item_1705708800000"