• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

count seconds to minutes

Hi experts! How can you count seconds to minutes and hours?
I would like the script to change let's say  601 seconds to:
10:01,
but if there is less than a minute to let's say 44 seconds to:
0:44
how? :)
0
vidda22
Asked:
vidda22
2 Solutions
 
hieloCommented:
For the "conversion":
http://us3.php.net/manual/en/function.strtotime.php

For the formatting:
http://us3.php.net/manual/en/function.date.php
<?php
echo date('H:i:s', strtotime("today +601 seconds") );
?>

Open in new window

0
 
sivagnanam chandrakanthTechnical LeadCommented:
<?php
$seconds=601;
if($seconds>60)
echo format_number($seconds/60);
else
echo "0.".$seconds;

function format_number($number) {
      $number = round($number,2);
      $number = number_format($number,2);
return $number;
}
?>
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Rok-KraljCommented:
Simple as that:
$num=601;

echo floor($num/60), ':', ($num%60);

Open in new window

0
 
Rok-KraljCommented:
Or if you want the padding:
function fmt($num) {
     return sprintf("%02d", $num);
}

$num=601;
echo fmt(floor($num/60)), ':', fmt($num%60);

Open in new window

0
 
vidda22Author Commented:
Rok-Kralj you really rock :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now