469,293 Members | 1,319 Online

# Milliseconds to HH:MM:SS ?? 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 19660 ronverdonk
4,258 Expert 4TB
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
1. divide your field by milliseconds per hour (1000*60*60) => hrs
2. divide rest by milliseconds per minute (1000*60)        => mins
3. divide rest by milliseconds per second (1000)           => secs
4. remains                                                 => millisecs
Ronald :cool:
Feb 11 '07 #2
sunbin
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]
<?php
//milliseconds to hh:mm:ss by <sunbin>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
ronverdonk
4,258 Expert 4TB
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]<?php
// ------------------------------------------------
// Calculate HH:MM:SS:TH from time in milliseconds
// ------------------------------------------------

// setup the test time 13:44:21:33
\$mytime = (1000 * 60 * 60 * 13) + (1000 * 60 * 44) + (1000 * 21) + 333; initialize the constants
\$msec_hh = 1000 * 60 * 60; // millisecs per hour
\$msec_mm = 1000 * 60; // millisecs per minute
\$msec_ss = 1000; // millisecs per second

//----------------------------
// Method 1 indirect
// ---------------------------
// calculate HH:MM:SS:TH
\$hh = \$mytime / \$msec_hh; // divide by millisecs per hour => 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("<br>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
sunbin
7 ThanX ronverdonk for ur ideas !

I expect the same again and again !

Sunbin
Feb 19 '07 #5
{"ft_lang_label":"__label__en","ft_lang_prob":0.5957792,"math_prob":0.945044,"size":1809,"snap":"2021-43-2021-49","text_gpt3_token_len":546,"char_repetition_ratio":0.23268698,"word_repetition_ratio":0.027681662,"special_character_ratio":0.45550027,"punctuation_ratio":0.16720258,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9764199,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-20T05:13:51Z\",\"WARC-Record-ID\":\"<urn:uuid:be4cdc28-c82f-4a8c-9343-4b667642071d>\",\"Content-Length\":\"51061\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5bae48d6-c4c2-45f5-8caf-002edbc9a85c>\",\"WARC-Concurrent-To\":\"<urn:uuid:8a227996-3fa4-4969-a6e2-9a16738d07f4>\",\"WARC-IP-Address\":\"104.197.32.212\",\"WARC-Target-URI\":\"https://bytes.com/topic/php/answers/600455-milliseconds-hh-mm-ss\",\"WARC-Payload-Digest\":\"sha1:SRXIUGXCUYTZHAECP4H6JEC5VV6LF4TY\",\"WARC-Block-Digest\":\"sha1:HINLUKSDFYPUTKJKVDGKYVETNBA3CFEH\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585302.56_warc_CC-MAIN-20211020024111-20211020054111-00622.warc.gz\"}"}