docs/reference/compat/util/now.md
::: warning Use Date.now() instead
This now function is a simple wrapper that calls Date.now() and represents unnecessary abstraction.
Use the faster and more direct Date.now() instead.
:::
Returns the current time in milliseconds.
const currentTime = now();
now()Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC. This is useful for time measurement and timestamp generation.
import { now } from 'es-toolkit/compat';
// Get the current time
const currentTime = now();
console.log(currentTime); // => 1703925600000 (example)
// Measure execution time
const startTime = now();
// Some time-consuming operation
const endTime = now();
console.log(`Operation time: ${endTime - startTime}ms`);
// Use as timestamp
const timestamp = now();
const logMessage = `[${timestamp}] Operation completed`;
Returns the same result as Date.now().
import { now } from 'es-toolkit/compat';
console.log(now() === Date.now()); // => true (when called at the same time)
None.
(number): Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC to the present.