Jump to content

Archived

This topic is now archived and is closed to further replies.

stupidfly

Seconds to Minutes

Recommended Posts

I know how to do this in Java, but it seems to be different in PHP.

I have a given number of seconds. Say 140. I want to display it as 2:20.

Share this post


Link to post
Share on other sites
try
[code]$sec = 140;

$min = floor($sec/60);
$sec = $sec % 60;

printf ('%0d:%02d', $min, $sec);[/code]

Share this post


Link to post
Share on other sites
Well it is truncating the tenths and hundreths of a second. I want to be able to display the decimals.

Share this post


Link to post
Share on other sites
There are none, that was just an example. Use 101.11 as an example then. I need it to at least go to hundreths.

Thanks

Share this post


Link to post
Share on other sites
As an example it wasn't very representative. Now I have to answer your question twice :-/

[code]$secs = 101.11;

$mins = floor($secs/60);

$secs -= $mins*60;

printf ('%0d:%02.2f', $mins, $secs);[/code]

Share this post


Link to post
Share on other sites
Well it is working, but when the seconds are less than ten, it doesn't display the zero. For 4:04.86, it displays 4:4.86.

Share this post


Link to post
Share on other sites
Odd. I tested with

[code]$secs = 120.11;

$mins = floor($secs/60);

$secs -= $mins*60;

printf ('%0d:%02.2f', $mins, $secs);[/code]

and got --> 2:00.11

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.