API Reference

Date-fns

Modern JavaScript date utility library providing modular, immutable, and tree-shakeable functions for date manipulation.

Official Documentation ↗
CompatibilityThis documentation covers version v3.6. Check the official docs for the latest API surface.

Installation

npmnpm install date-fns
pnpmpnpm add date-fns
yarnyarn add date-fns

Methods

Date-fns is a modern JavaScript date utility library that provides modular, immutable, and tree-shakeable functions for date manipulation and formatting. Unlike Moment.js, date-fns uses native Date objects and allows you to import only the functions you need.

Key Features

  • Modular: Tree-shakeable imports for minimal bundle size
  • Immutable: Functions never mutate input dates
  • Pure functions: No side effects, easy to test and reason about
  • TypeScript support: Full type definitions included
  • Unicode tokens: Standardized format tokens (yyyy, MM, dd, HH, mm, ss)
  • Localization: 32+ locales available via separate imports

FAQ

How does date-fns compare to Moment.js?
date-fns is modular and tree-shakeable (import only what you use), while Moment.js bundles everything. date-fns uses native Date objects instead of a custom wrapper, resulting in smaller bundle sizes and better performance.
Is date-fns immutable?
Yes. date-fns functions never mutate the input date. They always return a new Date object, which prevents accidental side effects and makes debugging easier.
How do I handle timezones with date-fns?
Use date-fns-tz for IANA timezone support. It provides zonedTimeToUtc and utcToZonedTime functions. Alternatively, use the built-in Intl API with formatInTimeZone for formatting.