stupidfly Posted March 4, 2006 Share Posted March 4, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/4069-seconds-to-minutes/ Share on other sites More sharing options...
Barand Posted March 4, 2006 Share Posted March 4, 2006 try[code]$sec = 140;$min = floor($sec/60);$sec = $sec % 60;printf ('%0d:%02d', $min, $sec);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4069-seconds-to-minutes/#findComment-14122 Share on other sites More sharing options...
stupidfly Posted March 4, 2006 Author Share Posted March 4, 2006 Well it is truncating the tenths and hundreths of a second. I want to be able to display the decimals. Quote Link to comment https://forums.phpfreaks.com/topic/4069-seconds-to-minutes/#findComment-14239 Share on other sites More sharing options...
Barand Posted March 4, 2006 Share Posted March 4, 2006 Where are the tenths and hundredths in "140"? Quote Link to comment https://forums.phpfreaks.com/topic/4069-seconds-to-minutes/#findComment-14240 Share on other sites More sharing options...
stupidfly Posted March 4, 2006 Author Share Posted March 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4069-seconds-to-minutes/#findComment-14242 Share on other sites More sharing options...
Barand Posted March 4, 2006 Share Posted March 4, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/4069-seconds-to-minutes/#findComment-14245 Share on other sites More sharing options...
stupidfly Posted March 4, 2006 Author Share Posted March 4, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/4069-seconds-to-minutes/#findComment-14250 Share on other sites More sharing options...
Barand Posted March 4, 2006 Share Posted March 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4069-seconds-to-minutes/#findComment-14257 Share on other sites More sharing options...
stupidfly Posted March 4, 2006 Author Share Posted March 4, 2006 Hmm... well thanks for your help. I'll just have to fiddle with it I guess. Quote Link to comment https://forums.phpfreaks.com/topic/4069-seconds-to-minutes/#findComment-14258 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.