moment
Moment.js is a JavaScript date library for parsing, validating, manipulating, and formatting dates that was the standard date handling library for JavaScript ap…
Installation
npm install moment
yarn add moment
pnpm add moment
Import
import moment from 'moment';
Quick Example
import moment from 'moment';
const now = moment();
console.log(now.format('MMMM Do YYYY, h:mm:ss a'));
console.log(moment('2024-06-15').fromNow());
console.log(now.add(7, 'days').calendar());About moment
Moment.js is a JavaScript date library for parsing, validating, manipulating, and formatting dates that was the standard date handling library for JavaScript applications for nearly a decade. Moment provides an intuitive chaining API: moment().add(7, 'days').format('MMMM Do YYYY'). The library handles parsing from multiple formats, timezone conversions (via moment-timezone), relative time display ('3 hours ago'), calendar formatting, locale-aware date display for over 100 locales, duration calculations, and comprehensive comparison utilities. Moment.js is now in maintenance mode — the maintainers recommend using modern alternatives like date-fns, Day.js, or Luxon for new projects. The primary concerns with Moment.js are its large bundle size (around 67KB minified plus locale data), its mutable API design which can lead to subtle bugs when date objects are shared, and its monolithic architecture that prevents tree shaking. Despite being in maintenance mode, Moment.js remains one of the most downloaded npm packages due to its extensive use in existing codebases and as a dependency of popular libraries like react-datepicker and FullCalendar.
Quick Facts
| Package | moment |
| Category | Utility |
| Weekly Downloads | 20M+ |
| License | MIT |
| Install | npm install moment |
Related Packages
Day.js is a minimalist JavaScript library for parsing, validating, manipulating, and formatting date…
date-fns is a modern JavaScript date utility library that provides comprehensive, consistent, and mo…
Lodash is the most popular JavaScript utility library, providing a comprehensive collection of funct…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.