473,372 Members | 1,062 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Milliseconds to HH:MM:SS ??

sunbin
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 21077
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

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Krzysztof Skibniewski | last post by:
Hello, I'm trying find out how to obtain and output that format ( hh:mm:ss.fff ) in my ASP. if somebody knows, pls let me know.. thx kris
2
by: D. Shane Fowlkes | last post by:
Here's a good one. I've been using an Excel spreadsheet for the past couple of years to calculate a file's Estimated Download Time based off of a solid 50kbs connection (dial up). This is for a...
6
by: Able | last post by:
Dear friends I need to format seconds as hh:mm:ss. I see a lot of coding transforming seconds to hh:mm:ss. Somebody know a short way? Regards Able
14
by: Michael Barrido | last post by:
I have this for example: Dim iSeconds as int32 = 3600 '3600 seconds is one hour How do i convert it to "01:00:00" ? Please help. Thanks in advance!
1
by: Jason Chan | last post by:
DateTime mydate = new DateTime(2006,1,1,0,0,0); string testStr = mydate.ToString("hh:mm:ss"); //return 12:00:00 mydate = new DateTime(2006,1,1,1,0,0) testStr = mydate.ToString("hh:mm:ss");...
5
by: kpp9c | last post by:
Hi, I was looking at python & datetime and hoping that it would already have a method/func to translate time formats. I need to translate seconds to hh:mm:ss.ms and vice versa and would like...
11
by: neelsfer | last post by:
how add (longtime) totaltime = + in query; i need to be able to add more than 24hrs also but it can still show in this format ie (hh:mm:ss) 31:10:20 = 31hrs 10min 20sec pls help
4
by: neelsfer | last post by:
I first deducted the laptime and actualstarttime of a race in a query using this formula and it gives me a correct lap1time value Lap1Time:nz(Format(-,"hh:nn:ss")) = 00:51:54 if i repeat this...
2
by: neelsfer | last post by:
I have a timing program. My next challenge is to convert hh:mm:ss into seconds. A user of my program wants to calculate watts for a hill climb race. the formula i am going to use is: =athlete...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.