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"