JavaScript Basics

JavaScript Advanced

JavaScript Arrays

JavaScript Functions

JavaScript Objects

JavaScript DOM

JavaScript String

How to convert Days to Seconds in JavaScript?

You should know that there are 24 hours in a day, 60 minutes in an hour, and 60 seconds in a minute. So, to convert days to seconds, multiply the days by 24, 60, and 60.

seconds = days * 24 * 60 * 60

The result that you obtained after the multiplication is actually the seconds equivalent of the number of days.

let days = 1;
let seconds;

seconds = days * 24 * 60 * 60;
console.log(seconds); //86400

days = 7;
seconds = days * 24 * 60 * 60;
console.log(seconds); //604800

days = 14;
seconds = days * 24 * 60 * 60;
console.log(seconds); //1209600

As you can see that the JavaScript code has given the correct result. 1 day has 86400 seconds, a week has 604800 seconds, and a fortnight has 1209600 seconds.

Recommended Posts