how to use the nextday function from the date-fns library in typescript

To use the nextDay function from the date-fns library in TypeScript, follow these steps:

  1. Install the date-fns library:
index.ts
npm install date-fns
21 chars
2 lines
  1. Import the function:
index.ts
import { nextDay } from 'date-fns';
36 chars
2 lines
  1. Use the function:
index.ts
const tomorrow = nextDay(new Date());
console.log(tomorrow);
61 chars
3 lines

The nextDay function takes a Date object as an argument and returns a new Date object, one day later. Note that the Date object passed to the function is not mutated.

Make sure to install the correct types for date-fns. If you are using TypeScript 3.2 or higher, you can install the types with:

index.ts
npm install --save-dev @types/date-fns
39 chars
2 lines

With these steps, you should be able to use the nextDay function from the date-fns library in TypeScript.

gistlibby LogSnag