Moment.js parses, validates, manipulates, and displays dates in JavaScript runtimes. It includes locale packs for wide-ranging calendar and relative-time output.
Overview
Moment.js is a JavaScript library focused on everyday date and time tasks in applications and scripts. You construct moment objects from strings with explicit formats, native Date values, or timestamps, then format output, compare instants, or shift values along calendar units.
Formatting helpers cover fixed patterns, localized short and long styles, and calendar phrases such as "yesterday" or "next week" relative to now. Relative-time APIs express deltas like "a few seconds ago" once the reference moment is set.
A separate bundle ships extensive locale data so the same API can render month names, meridiems, and weekday labels across many languages and regional variants. Callers can switch the active locale globally before formatting.
Project maintainers classify Moment.js as a legacy codebase in maintenance mode: existing behavior is supported, but new features are not accepted. Consumers are steered toward the status documentation for current guidance. Installation is available through common JavaScript package managers.
Key features
- Parse dates with custom formats
- Format fixed and localized strings
- Relative and calendar time phrasing
- Add and subtract date units
- Start and end of period helpers
- Wide locale pack support
- Mutable and immutable-style chaining
- Works in browsers and Node-style environments
Use cases
- Displaying timestamps in web UIs
- Converting user-entered date strings
- Showing how long ago events occurred
- Localizing date output per language