Convert Days to Milliseconds/Seconds/Minutes in JavaScript

avatar
Borislav Hadzhiev

Last updated: Mar 6, 2024
4 min

banner

# Table of Contents

  1. Convert Days to Milliseconds in JavaScript
  2. Convert Days to Seconds using JavaScript
  3. Convert Days to Minutes using JavaScript

# 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

convert days to milliseconds

The code for this article is available on GitHub

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

convert days to seconds using javascript

The code for this article is available on GitHub

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

convert days to minutes

The code for this article is available on GitHub

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 code for this article is available on GitHub

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.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev