Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  22] [ 6]  / answers: 1 / hits: 27859  / 12 Years ago, wed, november 28, 2012, 12:00:00

In JavaScript I have a variable Time in milliseconds.



I would like to know if there is any build-in function to convert efficiently this value to Minutes:Seconds format.



If not could you please point me out a utility function.



Example:



FROM



462000 milliseconds


TO



7:42

More From » javascript

 Answers
75

Thanks guys for your support, at th end I came up with this solution. I hope it can helps others.



Use:



var videoDuration = convertMillisecondsToDigitalClock(18050200).clock; // CONVERT DATE TO DIGITAL FORMAT





// CONVERT MILLISECONDS TO DIGITAL CLOCK FORMAT
function convertMillisecondsToDigitalClock(ms) {
hours = Math.floor(ms / 3600000), // 1 Hour = 36000 Milliseconds
minutes = Math.floor((ms % 3600000) / 60000), // 1 Minutes = 60000 Milliseconds
seconds = Math.floor(((ms % 360000) % 60000) / 1000) // 1 Second = 1000 Milliseconds
return {
hours : hours,
minutes : minutes,
seconds : seconds,
clock : hours + : + minutes + : + seconds
};
}

[#81759] Monday, November 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trayvon

Total Points: 35
Total Questions: 117
Total Answers: 88

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;