1 | 🔥️ **NEW**: [date-fns v4.0 with first-class time zone support is out!](https://blog.date-fns.org/v40-with-time-zone-support/)
|
2 |
|
3 | <img alt="date-fns" title="date-fns" src="https://raw.githubusercontent.com/date-fns/date-fns/master/docs/logotype.svg" width="150" />
|
4 |
|
5 | date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js
|
6 |
|
7 | 👉 [Documentation](https://date-fns.org/)
|
8 |
|
9 | 👉 [Blog](https://blog.date-fns.org/)
|
10 |
|
11 | <hr>
|
12 |
|
13 | It's like [Lodash](https://lodash.com) for dates
|
14 |
|
15 | - It has [**200+ functions** for all occasions](https://date-fns.org/docs/Getting-Started/).
|
16 | - **Modular**: Pick what you need. Works with webpack, Browserify, or Rollup and also supports tree-shaking.
|
17 | - **Native dates**: Uses existing native type. It doesn't extend core objects for safety's sake.
|
18 | - **Immutable & Pure**: Built using pure functions and always returns a new date instance.
|
19 | - **TypeScript**: The library is 100% TypeScript with brand-new handcrafted types.
|
20 | - **I18n**: Dozens of locales. Include only what you need.
|
21 | - [and many more benefits](https://date-fns.org/)
|
22 |
|
23 | ```js
|
24 | import { compareAsc, format } from "date-fns";
|
25 |
|
26 | format(new Date(2014, 1, 11), "yyyy-MM-dd");
|
27 | //=> '2014-02-11'
|
28 |
|
29 | const dates = [
|
30 | new Date(1995, 6, 2),
|
31 | new Date(1987, 1, 11),
|
32 | new Date(1989, 6, 10),
|
33 | ];
|
34 | dates.sort(compareAsc);
|
35 | //=> [
|
36 | // Wed Feb 11 1987 00:00:00,
|
37 | // Mon Jul 10 1989 00:00:00,
|
38 | // Sun Jul 02 1995 00:00:00
|
39 | // ]
|
40 | ```
|
41 |
|
42 | The library is available as an [npm package](https://www.npmjs.com/package/date-fns).
|
43 | To install the package run:
|
44 |
|
45 | ```bash
|
46 | npm install date-fns --save
|
47 | ```
|
48 |
|
49 | ## Docs
|
50 |
|
51 | [See date-fns.org](https://date-fns.org/) for more details, API,
|
52 | and other docs.
|
53 |
|
54 | <br />
|
55 |
|
56 | ## License
|
57 |
|
58 | [MIT © Sasha Koss](https://kossnocorp.mit-license.org/)
|