Date and Time operations in JavaScript – date-fns

Complete and awesome utility library for date and time operations in JavaScript. Meet “date-fns”.

Modern date and time JS/es6 utility

The “date-fns” provides the most comprehensive, yet simple and consistent tool-set for manipulating JavaScript dates and time. Both in a browser & node.js! What the developer can find there?

Modular, Native Date (date-fns doesn’t reinvent the wheel and uses the existing native type), Immutable & Pure (date-fns is built using pure functions and always returns a new date instance instead of changing the passed one), I18n(!).

It is consistent and reliable, with very good, detailed documentation.

Date and Time operations in JavaScript - date-fns
Date and Time operations in JavaScript – date-fns

Setup

npm install date-fns --save

# or with yarn
yarn add date-fns

# or with bower
bower install date-fns

Sample

import {format, compareAsc} from 'date-fns/esm';

format(new Date(2014, 1, 11), 'MM/dd/yyyy');
//=> '02/11/2014'

const dates = [new Date(1995, 6, 2), new Date(1987, 1, 11),
                new Date(1989, 6, 10)];

dates.sort(compareAsc);
//=> [
//   Wed Feb 11 1987 00:00:00,
//   Mon Jul 10 1989 00:00:00,
//   Sun Jul 02 1995 00:00:00
// ]

License: MIT

Homepage

https://date-fns.org

Docs

https://date-fns.org/docs/Getting-Started

GitHub

https://github.com/date-fns/date-fns

See also

Modern jQuery date picker plugin – DateSelect

Work with date and time in JavaScript? Try moment.js!

Time difference in words: jQuery fuzzy timestamps plugin – timeago

Material time picker library – a timer picker written in ES6 and SASS

jQuery countdown timer plugins

Enjoy & code!