Parse, validate, manipulate, and display dates in javascript.
open sourceMITself-hostablefree
Moment.js is a JavaScript library for parsing, validating, manipulating and formatting dates, in browsers and Node.js. It parses strings in many formats, does date arithmetic, shows relative and calendar times such as "3 days ago" or "Yesterday at 2:30 PM", handles durations and ships locale files for many languages; time zones come from the separate Moment Timezone plugin. Its maintainers call it a legacy project in maintenance mode: since September 2020 it takes no new features, and the August 2026 status update keeps critical security fixes and time zone data updates going, possibly in a maintenance-only 3.0. Moment objects are mutable, and the project belongs to the OpenJS Foundation.
Problems it solves
- parse dates that users type in lots of different formats in JavaScript
- show timestamps on a web page as '5 minutes ago' or 'in 3 days'
- add or subtract days, months and years from a date in JS without off-by-one mistakes
- format dates for display in the visitor's own language and locale
- check whether a date string someone entered is actually a valid date
- work out the difference between two dates in days, weeks or months
- print a duration like 1 hour 30 minutes in a human-friendly way
- compare dates in JavaScript: is this one before, after or between two others
- get the start or end of the week, month or quarter for a report
- show calendar-style dates like 'Yesterday at 2:30 PM' or 'Last Monday'
- date code that still has to run in very old browsers such as Internet Explorer
- keep an older app's date handling working without rewriting it for a newer library
Features
- parsing from strings, formats, arrays, objects, timestamps and Date objects, with validation
- formatting with format tokens
- relative time (fromNow, from, toNow, to) and calendar time
- date arithmetic and start or end of a unit
- comparison queries such as isBefore, isSame and isBetween
- durations with humanize and arithmetic
- locale files loaded one by one, or all in moment-with-locales
- custom locales: month names, relative time strings, calendar formats, eras
- time zones through the Moment Timezone plugin
- community plugins, including Hijri and Jalaali calendars
View 2 more
- TypeScript declarations in the package
- CommonJS, AMD (RequireJS) and browser global builds
Limitations
- No new features: Moment.js is a legacy project in maintenance mode, taking only maintenance work, critical security fixes and time zone data updates1
- Mutable date objects: manipulation methods change the original moment instead of returning a copy2
- No native ES module entry point: Moment is published as CommonJS, and Node.js imports it through CommonJS interop2
Capabilities
| Has an API | plan not known |
|---|---|
| Takes plugins | plan not known |
Alternatives
The same job
These do what Moment.js does.
