date-fns

4.1.0 · active · verified Sat Apr 18

date-fns is a modern, modular JavaScript utility library providing over 200 functions for manipulating dates in browsers and Node.js. It operates on native `Date` objects, ensuring immutability and purity, and offers full TypeScript support and internationalization. The current stable version is 4.1.0, which includes first-class time zone support (introduced in v4.0.0), and the project maintains a faster release cadence compared to earlier major versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `format` to reformat a date string and `compareAsc` to sort an array of `Date` objects.

import { compareAsc, format } from "date-fns";

// Format a specific date
console.log(format(new Date(2014, 1, 11), "yyyy-MM-dd"));
//=> '2014-02-11'

// Sort an array of dates
const dates = [
  new Date(1995, 6, 2),
  new Date(1987, 1, 11),
  new Date(1989, 6, 10),
];
dates.sort(compareAsc);
console.log(dates);
//=> [
//   Wed Feb 11 1987 00:00:00 GMT+...,
//   Mon Jul 10 1989 00:00:00 GMT+...,
//   Sun Jul 02 1995 00:00:00 GMT+...
// ]

view raw JSON →