Open navigation menu

Date-fns

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

Version: v3.6

Official Documentation ↗

Installation

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

Methods

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.