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

To use millisecondsToMinutes function from date-fns library in TypeScript, you can follow the below steps:

  1. Install date-fns using the following command:
index.ts
npm install date-fns
21 chars
2 lines
  1. Import millisecondsToMinutes function from date-fns in your TypeScript file using the following code:
index.ts
import { millisecondsToMinutes } from 'date-fns';
50 chars
2 lines
  1. Call the millisecondsToMinutes function with the number of milliseconds as the argument and it returns the equivalent number of minutes:
index.ts
const milliseconds = 30000;
const minutes = millisecondsToMinutes(milliseconds);
console.log(minutes); // Output: 0.5
118 chars
4 lines

Here's the complete example:

index.ts
import { millisecondsToMinutes } from 'date-fns';

const milliseconds = 30000;
const minutes = millisecondsToMinutes(milliseconds);
console.log(minutes); // Output: 0.5
169 chars
6 lines

This code converts milliseconds to minutes using the millisecondsToMinutes function from date-fns library in TypeScript.

gistlibby LogSnag