Date-fns
Modern JavaScript date utility library providing modular, immutable, and tree-shakeable functions for date manipulation.
Version: v3.6
Official Documentation ↗Installation
npm
npm install date-fnspnpm
pnpm add date-fnsyarn
yarn add date-fnsMethods
No methods match this filter.
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.