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"