Convert Days to Milliseconds/Seconds/Minutes in JavaScript

Last updated: Mar 6, 2024
4 min

#Convert days to milliseconds in JavaScript

To convert days to milliseconds, multiply the days by 24 for the hours, 60 for the minutes, 60 for the seconds and 1000 for the milliseconds.

index.js
function daysToMilliseconds(days) { // ๐๏ธ hour min sec ms return days * 24 * 60 * 60 * 1000; } console.log(daysToMilliseconds(1)); // ๐๏ธ 86400000 console.log(daysToMilliseconds(2)); // ๐๏ธ 17280000 console.log(daysToMilliseconds(5)); // ๐๏ธ 432000000

We created a reusable function that takes the number of days as a parameter and converts the days to milliseconds.

To convert the days to milliseconds, we have to multiply by 24 to convert to hours, 60 to convert to minutes, 60 to convert to seconds and 1000 to convert to milliseconds.

If your application uses fractional units for the days, you might get a decimal number after the conversion.

index.js
function daysToMilliseconds(days) { // ๐๏ธ hour min sec ms return days * 24 * 60 * 60 * 1000; } console.log(daysToMilliseconds(5.5612)); // ๐๏ธ 442367999.99999

You can use the Math.round() function to round the number to the nearest integer.

index.js
function daysToMilliseconds(days) { // ๐๏ธ hour min sec ms return Math.round(days * 24 * 60 * 60 * 1000); } console.log(daysToMilliseconds(5.5612)); // ๐๏ธ 442368000

We passed the value to the Math.round function to round to the nearest integer and make sure we don't get a decimal after the conversion.

Here are some examples of how the Math.round function works.

index.js
console.log(Math.round(3.49)); // ๐๏ธ 3 console.log(Math.round(3.5)); // ๐๏ธ 4

The function rounds the number up or down to the nearest integer.

If the number is positive and its fractional part is greater than or equal to 0.5, it gets rounded to the next higher absolute value.

If the number is positive and its fractional portion is less than 0.5, it gets rounded to the lower absolute value.

#Convert days to seconds using JavaScript

To convert days to seconds, multiply the days by 24 for the hours, 60 for the minutes and 60 for the seconds.

The result from the multiplication will represent the seconds equivalent of the number of days.

index.js
function daysToSeconds(days) { // ๐๏ธ hour min sec return days * 24 * 60 * 60; } console.log(daysToSeconds(1)); // ๐๏ธ 86400 console.log(daysToSeconds(2)); // ๐๏ธ 172800 console.log(daysToSeconds(5)); // ๐๏ธ 432000

We created a reusable function that takes the number of days as a parameter and converts the days to seconds.

To convert the days to seconds, we have to multiply by 24 to convert to hours, 60 to convert to minutes and 60 to convert to seconds.

If your application uses fractional units for the days, you might get a decimal number after the conversion.

index.js
function daysToSeconds(days) { // ๐๏ธ hour min sec return days * 24 * 60 * 60; } console.log(daysToSeconds(3.5612)); // ๐๏ธ 307687.68

You can use the Math.round() function to round the number to the nearest integer.

index.js
function daysToSeconds(days) { // ๐๏ธ hour min sec return Math.round(days * 24 * 60 * 60); } console.log(daysToSeconds(3.5612)); // ๐๏ธ 307688

We passed the value to the Math.round function to round to the nearest integer and make sure we don't get a decimal after the conversion.

Here are some examples of how the Math.round() function works.

index.js
console.log(Math.round(7.49)); // ๐๏ธ 7 console.log(Math.round(7.5)); // ๐๏ธ 8

The function rounds the number up or down to the nearest integer.

If the number is positive and its fractional part is greater than or equal to 0.5, it gets rounded to the next higher absolute value.

If the number is positive and its fractional portion is less than 0.5, it gets rounded to the lower absolute value.

#Convert Days to Minutes using JavaScript

To convert days to minutes, multiply the days by 24 for the hours and 60 for the minutes.

The result from the multiplication will represent the minutes equivalent of the number of days.

index.js
function daysToMinutes(days) { // ๐๏ธ hour min return days * 24 * 60; } console.log(daysToMinutes(1)); // ๐๏ธ 1440 console.log(daysToMinutes(2)); // ๐๏ธ 2880 console.log(daysToMinutes(5)); // ๐๏ธ 7200

We created a reusable function that takes the number of days as a parameter and converts the days to minutes.

To convert the days to minutes, we have to multiply by 24 to convert to hours and 60 to convert to minutes.

If your application uses fractional units for the days, you might get a decimal number after the conversion.

index.js
function daysToMinutes(days) { // ๐๏ธ hour min return days * 24 * 60; } console.log(daysToMinutes(3.43)); // ๐๏ธ 4939.20000001

You can use the Math.round() function to round the number to the nearest integer.

index.js
function daysToMinutes(days) { // ๐๏ธ hour min return Math.round(days * 24 * 60); } console.log(daysToMinutes(3.43)); // ๐๏ธ 4939

We passed the value to the Math.round function to round to the nearest integer and make sure we don't get a decimal after the conversion.

Here are some examples of how the Math.round function works.

index.js
console.log(Math.round(2.49)); // ๐๏ธ 2 console.log(Math.round(2.5)); // ๐๏ธ 3

The function rounds the number up or down to the nearest integer.

If the number is positive and its fractional part is greater than or equal to 0.5, it gets rounded to the next higher absolute value.

If the number is positive and its fractional portion is less than 0.5, it gets rounded to the lower absolute value.