Socket
Socket
Sign inDemoInstall

date-fns

Package Overview
Dependencies
0
Maintainers
2
Versions
200
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    date-fns

Modern JavaScript date utility library


Version published
Weekly downloads
19M
increased by3.19%
Maintainers
2
Install size
10.9 MB
Created
Weekly downloads
 

Package description

What is date-fns?

The date-fns npm package provides a comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js. It offers a variety of functions to parse, validate, manipulate, and format dates.

What are date-fns's main functionalities?

Parsing Dates

Parse strings in ISO format to JavaScript Date objects.

const parseISO = require('date-fns/parseISO');
const result = parseISO('2023-04-12');

Formatting Dates

Format Date objects into strings with a given format.

const format = require('date-fns/format');
const result = format(new Date(2023, 3, 12), 'yyyy-MM-dd');

Comparing Dates

Compare two dates to determine if one comes before the other.

const isBefore = require('date-fns/isBefore');
const result = isBefore(new Date(2023, 3, 12), new Date(2023, 3, 13));

Manipulating Dates

Perform date calculations such as adding or subtracting time spans.

const addDays = require('date-fns/addDays');
const result = addDays(new Date(2023, 3, 12), 10);

Validating Dates

Check if a date is valid.

const isValid = require('date-fns/isValid');
const result = isValid(new Date('2023-04-12'));

Other packages similar to date-fns

Readme

Source

date-fns

🔥🔥🔥 date-fns v2 is out! 🔥🔥🔥

⭐️ Upgrading from v1 to v2?

  • See the changelog
  • Check out @date-fns/upgrade and @date-fns/upgrade-codemod, they could help you with the upgrade!

date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.

date-fns is like lodash for dates. It has 180+ functions for all occasions.

import { compareAsc, format } from 'date-fns'

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

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
// ]

The library is available as an npm package. To install the package run:

npm install date-fns --save
# or with yarn
yarn add date-fns

Docs

See date-fns.org for more details, API, and other docs.

JavaScript jobs by date-fns

👋 Know someone who's looking for JavaScript devs? Recommend us a job!

✉️ Get jobs worth sharing to your email! Subscribe to the newsletter.

License

MIT © Sasha Koss

FAQs

Last updated on 17 Jul 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc