In this article we will learn how to convert days to minutes in JavaScript.
It is very common to convert days to minutes in JavaScript in JavaScript.
Problem
Now we have a problem, and it is that we want to convert days into minutes.
For example, if we have the number of days is three, then it will be in hours like this:
4320
And if we have the number of days is five:
7200
How to solve this problem?
This problem is very simple, all that is involved is a simple mathematical operation, to convert days into minutes first we have to multiply by 24 which is the number of hours and then multiply by 60 which is the number of minutes then you will get the result.
The solution will be as follows:
- multiply by 24 which is the number of hours
- multiply by 60 which is the number of minutes
Solution:
Let's see an example of solution:
// Define variables
const days = 5;
const hours = 24;
const min = 60;
// Get five days in minutes
console.log(days * hours * min);
Output
7200
Now you will probably use the code more than once, so we will create a function that calculates that result for us
Function
// Create a function
function convertToMins(days) {
const hours = 24;
const min = 60;
return days * hours * min;
}
// Tests
console.log(convertToMins(5));
console.log(convertToMins(3));
console.log(convertToMins(10));
Output
7200
4320
14400
Thank you for reading
Thank you for reading my blog. 🚀