PACKAGE · DATE & TIME

moment

Parse, validate, manipulate, and display dates

WEEKLY DOWNLOADS 51.4M
STARS 47.9K
FORKS 7.0K
OPEN ISSUES 70
GZIP SIZE 20.8 kB
UNPACKED SIZE 4.5 MB
DEPENDENCIES 1
LAST UPDATED 1y ago
DOWNLOAD TRENDS

moment downloads · last 12 months

Download trends for moment1 download series from Nov 2025 to Oct 2026. Use left and right arrow keys to inspect monthly values.045.9M91.8M137.7M183.6MNov 2025FebMayAugOct 2026
moment
ABOUT MOMENT

Moment parses, validates, manipulates, and displays dates and times in JavaScript. It provides a consistent API for common operations such as reading a date string, checking whether it is valid, changing a date, and formatting it for display.

Its design centers on a mutable date object and chainable methods, making sequences of date operations compact to write. This approach suits existing applications whose teams want a familiar, general-purpose date API, but it requires care when an operation should not alter a value that is reused elsewhere.

Typical code creates a value with moment(), moment(input), or moment(input, format), then checks it with isValid(), adjusts it with methods such as add(), subtract(), or startOf(), and formats it with format(). Moment also provides comparison and difference methods for tasks such as checking whether a date is before another date or calculating an interval.

Moment can be used directly in JavaScript applications, including interfaces that need to format dates for display and server-side code that parses or compares date values. Its API is independent of a particular application framework, so date handling can remain in utility functions or be called from framework components and other application workflows.

The supplied package data lists version 2.31.0, an MIT license, 14.9M weekly downloads, and a gzip bundle size of 20.8 kB. That bundle size is a practical consideration for browser applications with strict payload budgets; evaluate the actual import and delivery path in your build rather than assuming every application pays the same cost.

Moment is mutable, so chained operations can change the original value; use clone() before modifying a value that must be preserved. Its broad date-and-time API may also be unnecessary for applications that only need native date parsing or a narrow set of formatting operations, and date input formats should be chosen deliberately when predictable parsing is important.

WHEN TO USE
  • When maintaining an application that already uses Moment objects and chainable calls such as add(), subtract(), and format(), preserving the existing date-handling conventions can avoid a broad rewrite.
  • When rendering dates in a specified display pattern, use moment(value).format(pattern) to keep formatting logic close to the date value.
  • When accepting dates in a known string format, use moment(input, format) and check isValid() before using the result.
  • When calculating relative dates, use add() or subtract() with an explicit unit, such as days or months, instead of manually changing date fields.
  • When grouping or normalizing dates to a boundary, use startOf() or endOf() with a unit such as day or month.
  • When comparing dates or measuring elapsed time, use methods such as isBefore(), isAfter(), or diff() rather than comparing formatted strings.
  • When a date value must be adjusted without changing the original Moment object, call clone() before applying mutating methods.
WHEN NOT TO USE
  • If browser payload limits make Moment's listed 20.8 kB gzip bundle size unsuitable, assess a lighter date-handling approach or reduce the date functionality shipped to the client.
  • If application logic depends on immutable date values, Moment's mutating methods can cause unintended changes; use clone() consistently or choose an immutable date-handling approach.
  • If the application only needs basic date operations already covered by the JavaScript runtime, prefer native date APIs to avoid adding Moment as a dependency.
  • If inputs may use inconsistent or ambiguous date strings, avoid relying on implicit parsing; require a known input format and validate with isValid(), or use a parsing approach with stricter input rules.
  • If the project requires a narrow, purpose-built date API rather than Moment's general-purpose interface, compare the required operations with a more focused approach before adopting the full package.
  • If date values must retain their original state across multiple calculations, do not reuse a Moment object for chained mutations; clone it before each independent calculation or use immutable values.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 5
moment vs date-fns ★ 36.7K · 123.1M/wk moment vs luxon ★ 16.5K · 60.1M/wk moment vs @js-joda/core ★ 1.7K · 7.9M/wk moment vs dayjs ★ 48.6K · 114.1M/wk moment vs @formkit/tempo ★ 2.6K · 125.3K/wk