how to use the endofdecade function from date-fns in javascript

To use the endOfDecade function from date-fns in Javascript, you first need to install the date-fns library using a package manager such as NPM or Yarn.

npm install date-fns
21 chars
2 lines

Once date-fns is installed, you can import the endOfDecade function and use it in your code like this:

index.tsx
import { endOfDecade } from 'date-fns';

const date = new Date(2019, 6, 12); // July 12, 2019
const endOfDecadeDate = endOfDecade(date); // December 31, 2019

console.log(endOfDecadeDate); // Output: 2019-12-31T23:59:59.999Z
225 chars
7 lines

The endOfDecade function takes a date as an argument and returns a new Date object representing the last millisecond of the decade that the original date belongs to. In the example above, endOfDecadeDate will be a Date object representing December 31, 2019, which is the last day of the decade that includes the original date: July 12, 2019.

gistlibby LogSnag