473,796 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Milliseconds to HH:MM:SS ??

sunbin
7 New Member
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 21342
ronverdonk
4,258 Recognized Expert Specialist
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 New Member
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=90 0000;
$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 Recognized Expert Specialist
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("Durati on is %02s:%02s:%02s: %02s", (int)$hh, (int)$mm, (int)$ss, (int)$r);

//----------------------------
//method 2 direct
//----------------------------
echo sprintf("<br>Du ration 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 New Member
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
5524
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
2489
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 downloads page such as: http://www.drpt.virginia.gov/downloads/selectedcat.aspx?ID=12 The formula is basically this: =(((C4*1000*8)/50000)/84600)*1.1 (Estimate is calculated on a modem dial up connection of 50Kbs and transfer
6
3107
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
4101
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
2766
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"); //return 01:00:00 I want "00:00:00" instead of "12:00:00", what is going wrong?
5
10605
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 the ability to do some basic arithmetic in these formats. I think that there just has to be a package or module out there that already does this with reasonable speed and accuracy.
11
7461
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
2607
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 for lap2 to determine the lap2time value Lap2Time: Nz(Format(-,"hh:nn:ss")) = 00:00:03 and the 3rd lap = 00:00:03 It produces the correct time My problem is adding up these to laptimes to get a totaltime from the start. I dont want to just...
2
12086
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 weight (kg) x 9.8 x elevation gain (meters) / time (seconds) i have everything except the seconds. We use a special Garmin gps to calculate the elevation gain in meter and i get the weight of the athlete using a scale on the day of the race. I get...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9054
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.