Lodash Date methods
What you’ll learn
- What to know before you start (see Prerequisites).
- Why Lodash’s Date category is almost entirely about Unix millisecond timestamps.
- How
_.now()compares toDate.now()andperformance.now(). - Where to look outside Lodash for formatting, parsing, and time zones.
- Where this hub sits in the Lodash docs taxonomy and how imports stay tree-shakeable.
Prerequisites
Numbers in JavaScript, optional familiarity with Lodash collection tutorials, and realistic expectations: Lodash is not Moment.js.
- Unix milliseconds: timestamps from
Date.now()count milliseconds since 1970-01-01 UTC; they are numeric, easy to sort, and safe for JSON. - The Date object: constructing
new Date(), reading components in local time versus UTC, and knowing that invalid parses yieldInvalid Date. - Modules: ESM
importor CommonJSrequireso the snippets below match your bundler or Node project.
Key concepts
Three distinctions keep Date-adjacent code readable: what you are measuring, what clock backs it, and whether Lodash is involved at all.
Instant vs presentation
A single instant can be stored as ms since epoch. Turning it into “May 10, 2026 in Tokyo” is formatting—reach for Intl, Temporal, or a date library, not Lodash.
Wall clock vs monotonic
Date.now() and _.now() follow the system clock and can jump backward after adjustments. performance.now() in browsers is better for durations between two moments in one session.
Lodash’s narrow role
Lodash dates the category as “Date” in docs but ships one portable helper for current epoch ms. Everything richer stays in the language or ecosystem.
Overview
Use Lodash here when you already import the library and want a tiny, tree-shakeable alias for “right now in epoch milliseconds.” For locale-aware strings or recurring calendar rules, plan on native APIs or specialized packages.
IDs and ordering
Epoch ms works well for createdAt fields, rough versioning, and lexicographic sorts when converted to fixed-width strings.
Defer and throttle patterns
Lodash’s own examples pair _.now() with defer or timing utilities to measure elapsed ms—still about timestamps, not calendars.
Know the gaps
Parsing user-typed dates, DST edges, and recurring events need dedicated tooling; pretending Lodash covers them leads to subtle bugs.
⚖️ _.now vs native clocks
Pick the API that matches whether you need an absolute timestamp, a monotonic interval, or rich formatting.
| Goal | Typical choice | Notes |
|---|---|---|
| Persist “when this happened” as a number | Date.now() or _.now() | Same numeric meaning in Lodash 4.x; both are UTC epoch ms. |
| Measure how long a hot path takes | performance.now() (where available) | Monotonic; not interchangeable with epoch timestamps. |
| Display a localized date string | Intl.DateTimeFormat or Temporal | Lodash does not replace these layers. |
| Parse arbitrary user text safely | Strict parsers (libraries or Temporal) | Avoid relying on Date.parse alone for untrusted input. |
Install and import
Install the core package once, then import now directly so unused Lodash stays out of your bundle.
npm install lodash import now from "lodash/now";
const startedAt = now();
// same epoch-ms family as Date.now()
requestIdleCallback?.(() => {
console.log(now() - startedAt);
}); Suggested learning path
Lodash date coverage is intentionally small—pair it with platform APIs in this order.
- Timestamps: practice storing and comparing raw ms values alongside
Date.now()on MDN. - Display: format a fixed instant with
Intl.DateTimeFormatso locale behavior is explicit. - Durations: in browsers, contrast with
performance.now()for micro-benchmarks. - Ecosystem: reach for Temporal or a maintained date library when rules outgrow one-off formatting.
💻 Environment and versions
- Lodash 4.x:
_.nowis stable across environments that provideDate.now(modern browsers and Node). - Isomorphic code: both
Date.now()andlodash/nowbehave the same when the global Date object is standard. - TypeScript: typings ship with
@types/lodashfor namespace imports; per-method imports still benefit from those declarations.
Method index
Lodash lists one Date-category helper in 4.x in stable releases. Each row links to a focused tutorial on this site where available; URLs follow /lodash/date/{method-kebab}.
| Method | What it does |
|---|---|
_.now() | Returns the current time as milliseconds since the Unix epoch (delegates to Date.now()). |
Pitfalls to avoid
Trusting ms for strict ordering
Two calls in tight loops can yield identical timestamps; use counters or UUIDs when collisions matter.
Formatting with Lodash
String templates around new Date() without Intl quickly break for locales; plan formatting explicitly.
Implicit Date parsing
Feeding ambiguous strings into new Date(...) yields inconsistent results across engines—validate input.
❓ FAQ
Summary
- Scope: Lodash Date here means portable epoch-ms via
_.now(); calendars live elsewhere. - Bundles: import
lodash/nowwhen that is all you need. - Next step: bookmark Lodash _.now(), revisit Lodash Collection Methods, or follow the learning-path links above.
Under the hood, Lodash _.now() calls Date.now() on the global object—so numeric results match the native API; Lodash mainly gives you a consistent import surface inside larger chains.
7 people found this page helpful
