| What it is | Guide to replacing Moment.js with native Date, date-fns, Day.js or Luxon, plus an ESLint plugin that flags Moment.js calls | Fast 2kB alternative to Moment.js with the same modern API | Modern JavaScript date utility library | Parse, validate, manipulate, and display dates in javascript. |
| Features | - Why to replace Moment.js: tree-shaking, mutability, API complexity
- Comparison of Moment.js, Luxon, date-fns and Day.js
- Function-by-function equivalents in native JS and each library
- ESLint plugin that flags replaceable Moment.js calls
| - Moment.js-style API: parse, format, get and set, add and subtract, startOf and endOf, isBefore and isSame
- immutable, chainable objects
- core of about 2 kB
- ISO 8601 parsing by default; custom formats with the CustomParseFormat plugin
- locales loaded on demand, per instance or globally
- 35 official plugins, including Timezone, UTC, RelativeTime, Duration, Calendar, IsoWeek, QuarterOfYear and AdvancedFormat
- IANA time zone conversion with dayjs.tz, tz.guess and tz.setDefault (Timezone plugin)
- TypeScript declarations in the package
| - more than 200 functions: format, parse, add, sub, differenceIn*, isBefore, eachDayOfInterval, startOf*, endOf* and more
- works on native Date objects, no wrapper type
- pure, immutable functions that return a new date
- one module per function, tree-shakable; ESM-first with CommonJS builds
- written in TypeScript
- dozens of locales, included only when imported
- date-fns/fp: curried functions for composition
- time zones with TZDate (@date-fns/tz) and UTCDate (@date-fns/utc), or the in option on each function
- All 9 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
- All 12 features
|