Lodash _.now() method
What you’ll learn
- What
_.now()returns and why it lives under the Date category in Lodash docs. - How it relates to
Date.now()and whenperformance.now()is a better fit. - A defer-friendly pattern for measuring elapsed milliseconds between scheduling and execution.
- Try each example in the editor (
?tryit=1,2,3) with Lodash from a CDN.
Prerequisites
Optional read Lodash Date methods hub; you should be comfortable with plain numbers as timestamps (milliseconds).
- Unix epoch ms: understanding that
Date.now()counts milliseconds since 1970-01-01 UTC. - Modules: ability to run
import now from "lodash/now"in your bundler or open the Try-it HTML labs.
Overview
_.now() is Lodash’s portable name for the current wall-clock timestamp in epoch milliseconds. It performs no formatting, parsing, or locale work—only a thin wrapper so timers line up with other Lodash imports.
Instant stamp
Drop-in substitute for Date.now() when your module already standardizes on Lodash entry points.
Defer pairing
Lodash examples capture _.now(), schedule work with defer, then subtract inside the callback to measure scheduling delay.
Tree-shakeable
Import lodash/now alone—there is no hidden collection logic bundled behind this helper.
Syntax
_.now() - Arguments: none.
- Returns: a number—the milliseconds elapsed since the Unix epoch, same family as
Date.now(). - Category: Date in Lodash 4.x documentation.
Basic timestamp
Each call samples the host clock; values increase over real time but two ultra-close calls may collide when the clock granularity is coarse.
import now from "lodash/now";
const stamp = now();
// e.g. 1735689600000 — matches Date.now() on the same tick Defer delay (Lodash doc pattern)
Capture a stamp, schedule async-ish work with defer, then subtract inside the callback—classic Lodash documentation wording adapted here.
import defer from "lodash/defer";
import now from "lodash/now";
defer((stamp) => {
console.log(now() - stamp);
}, now());
// => Logs milliseconds between scheduling and callback run Metadata field
Stamp plain records before persistence or optimistic UI updates—still just a number, ready for JSON.
import now from "lodash/now";
function createDraft(body) {
return { body, createdAt: now(), status: "draft" };
} 📋 _.now vs Date.now() vs performance.now()
| API | Returns | Best for |
|---|---|---|
_.now() | Epoch ms (UTC) | Consistent Lodash import alongside other per-method imports |
Date.now() | Epoch ms (UTC) | Zero-dep stamps anywhere ECMAScript runs |
performance.now() | High-res ms since navigation start | Monotonic timing deltas in browsers (not JSON timestamps) |
Pitfalls to avoid
Same millisecond twice
High-frequency loops can log identical values; add a counter or UUID when uniqueness matters.
Wall-clock drift
NTP adjustments can move epoch ms backward—never assume strictly increasing time across reboots or sync events.
Formatting here
Pass stamps through Intl.DateTimeFormat, Temporal, or libraries when users need readable locale strings.
❓ FAQ
Summary
- Purpose:
_.now()returns current Unix epoch milliseconds by delegating toDate.now(). - Imports: prefer
lodash/nowfor tree shaking. - Next: Home, Lodash Date methods hub, or official Lodash docs for _.now.
Lodash implements _.now as root.Date.now(), so the numeric result tracks the native clock—the helper mainly exists for consistency when you already compose other Lodash utilities.
6 people found this page helpful
