date-fns
A set of small, tree-shakeable date functions instead of one big Moment-style object. Good when bundle size actually matters.
What is date-fns?
date-fns is a JavaScript library of small, pure functions for parsing, formatting, comparing, and manipulating dates, built as an alternative to bundling one large date object like Moment.js used to. Every function is independently importable, so your bundler only includes the specific operations you actually call (format, addDays, differenceInHours, and so on) instead of an entire date-handling runtime. It works with native JavaScript Date objects rather than introducing its own wrapper type.
Key features
- Fully tree-shakeable: import only the functions you use, and unused ones are stripped from your bundle
- Immutable functions that always return a new date rather than mutating the one you passed in
- Consistent, functional API (each function takes a date and returns a value) instead of chained methods
- Built-in internationalization and locale support for formatting dates in different languages
- TypeScript types included out of the box
Who it's for
Any JavaScript or TypeScript project where bundle size matters and you need real date math (not just display formatting), especially frontend apps shipping to the browser. For quick relative-time display alone, an even smaller single-purpose library might be enough; for heavy timezone-aware scheduling logic, pairing it with a timezone-specific library is common.
Pricing
Free and open-source.