1 second = 1,000 milliseconds | 15 minutes = 900,000 milliseconds |
30 seconds = 30,000 milliseconds | 30 minutes = 1,800,000 milliseconds |
1 minute = 60,000 milliseconds | 45 minutes = 2,700,000 milliseconds |
5 minutes = 300,000 milliseconds | 1 hour = 3,600,000 milliseconds |
Convert hours, minutes, and seconds into milliseconds: (then right-click and copy result) Hours + Minutes + Seconds = Milliseconds | |
Note: we added thousands-separating commas to make it easier to read - don't include numbers with commas (or spaces, like European convention) when you pass milliseconds to a timer. |
function msToHMS( ms ) {
// 1- Convert to seconds:
var seconds = ms / 1000;
// 2- Extract hours:
var hours = parseInt( seconds / 3600 ); // 3,600 seconds in 1 hour
seconds = seconds % 3600; // seconds remaining after extracting hours
// 3- Extract minutes:
var minutes = parseInt( seconds / 60 ); // 60 seconds in 1 minute
// 4- Keep only seconds not extracted to minutes:
seconds = seconds % 60;
alert( hours+" hours and "+minutes+" minutes and "+seconds+" seconds!" );
}
var timespan = 3723000; // duration in milliseconds
msToHMS( timespan );
msToHMS( 65000 );
Note: JavaScript's "modulus operator" (%) returns the remainder of an integer division.