438,521 Members | 1,420 Online Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

# Milliseconds to HH:MM:SS ??

 P: 7 hi, How can i get the FLV file or any type of video file's duration in HH:MM:SS or HH:MM:SS:FF format from milliosecond ? I already got duration in millisecond. PHP script needed ... Plz help me ! Sunbin Feb 11 '07 #1
4 Replies

 Expert 2.5K+ P: 4,258 We do not post code scripts here, we help members with the development of their code. So this you can script this yourself. Hint: Expand|Select|Wrap|Line Numbers divide your field by milliseconds per hour (1000*60*60) => hrs divide rest by milliseconds per minute (1000*60)        => mins divide rest by milliseconds per second (1000)           => secs remains                                                 => millisecs Ronald :cool: Feb 11 '07 #2

 P: 7 Thanks Ronverdonk, Finally, i developed a script block to convert millisecond into HH:MM:SS format. I develped this script to display a video file (.flv) duration in that format. My script blcok is : [php] sunbin.np@gmail.com \$miliseconds=900000; \$seconds= \$miliseconds/1000; //for seconds if(\$seconds> 0) { \$sec= "" . (\$seconds%60); if(\$seconds % 60 <10) { \$sec= "0" . (\$seconds%60); } } //for mins if(\$seconds > 60) { \$mins= "". (\$seconds/60%60); if((\$seconds/60%60)<10) { \$mins= "0" . (\$seconds/60%60); } } else { \$mins= "00"; } //for hours if(\$seconds/60 > 60) { \$hours= "". (\$seconds/60/60); if((\$seconds/60/60) < 10) { \$hours= "0" . (\$seconds/60/60); } } else { \$hours= "00"; } print \$time_format= "" . \$hours . ":" . \$mins . ":" . \$sec; //00:15:00 ?>[/php] - Sunbin Feb 16 '07 #3

 Expert 2.5K+ P: 4,258 This is one way of doing it, but it is a bit more lengthy than is needed. In the next sample I show you how you can do that a bit easier. But both methods start at the high end: begin to calculate the hours and then go downwards, as I showed you in my previous post. Method 1 calculates every value in a separate variable, and is outputted when all values have been calculated. Method 2 is a lot shorter, it displays the calculation direct to the screen. And when you want it shorter still, you can use the constant values directly in the method 2, but that makes it harder to read. [php] hrs \$r = \$mytime % \$msec_hh; \$mm = \$r / \$msec_mm; // divide rest by millisecs per minute => mins \$r = \$r % \$msec_mm; \$ss = \$r / \$msec_ss; // divide rest by millisecs per second => secs \$r = \$r % \$msec_ss; echo sprintf("Duration is %02s:%02s:%02s:%02s", (int)\$hh, (int)\$mm, (int)\$ss, (int)\$r); //---------------------------- //method 2 direct //---------------------------- echo sprintf("
Duration is %02s:%02s:%02s:%02s", (int)(\$mytime / \$msec_hh), (int)((\$mytime % \$msec_hh) / \$msec_mm), (int)(((\$mytime % \$msec_hh) % \$msec_mm) / \$msec_ss), (int)(((\$mytime % \$msec_hh) % \$msec_mm) % \$msec_ss) ); ?> [/php] Ronald :cool: Feb 16 '07 #4

 P: 7 ThanX ronverdonk for ur ideas ! I expect the same again and again ! Sunbin Feb 19 '07 #5 