import { format, formatDistance, formatRelative, subDays } from 'date-fns'
format(new Date(), "'Today is a' eeee")
//=> "Today is a Wednesday"
formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true })
//=> "3 days ago"
formatRelative(subDays(new Date(), 3), new Date())
//=> "last Friday at 7:26 p.m."
With the function-per-file style, you can pick just what you need and stop bloating your project with useless functionality.
Date
Functions in date-fns work predictably and stick to ECMAScript behavior in edge cases.
date-fns is built using pure functions and always returns a new date instance instead of changing the passed one.
It helps to prevent bugs and avoid long debugging sessions.
The typings are generated from the source code and bundled with the package, so they're always up-to-date.
date-fns always returns a date in the same time zone, no matter what's passed - a timestamp, a string or a date object.
The API is tailored to have predictable names and arguments order.
date-fns respects timezones & DST.
It follows semantic versioning so, always backward compatible.
Each build CI checks more than 650 000 examples in about 400 time zones.
The best API is an API that doesn't exist. With date-fns you always have one function that does one thing.
The API is unambiguous, and there is always a single approach to a problem.