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

To use the addMinutes function from date-fns, you need to first install the library by running npm install date-fns --save in your command line interface.

Then, you can import the addMinutes function in your JavaScript file by using:

index.tsx
import { addMinutes } from 'date-fns';
39 chars
2 lines

Alternatively, if you're not using a module bundler, you can include the date-fns library in your HTML file by adding:

<script src="https://cdn.jsdelivr.net/npm/date-fns@2.22.1"></script>
69 chars
2 lines

Once you've imported or included the date-fns library in your project, you can use the addMinutes function to add a specified number of minutes to a given date.

Here's an example:

index.tsx
const myDate = new Date('2021-07-01T11:30:00Z');
const newDate = addMinutes(myDate, 30);
console.log(newDate);
// Output: Thu Jul 01 2021 12:00:00 GMT+0000 (Coordinated Universal Time)
185 chars
5 lines

In this example, we're creating a new Date object with the value of '2021-07-01T11:30:00Z'. We then pass this date and the number 30 to the addMinutes function to add 30 minutes to the original date. The result is stored in the newDate variable, which is then logged to the console.

gistlibby LogSnag