Jump to content

Time Formatting


dean7

Recommended Posts

Hi all, I have features on my website which require a time limit untill they can do the thing agian, but at the current mintue ive got the time in seconds. How can I make a function which will give the time in minutes instaid of seconds.

 

Example:

 

If it was a 2 mintue waiting time instaid of being 120 Seconds it will be 2min(s) 0sec(s).

 

Example of my Current Code:

 

$timewaiting = time() + 160; // Waiting time. (2min)


if ($user->lasttime > time()){
$howlongleft = $user->lasttime - time();

echo ("You must wait $howlongleft");

 

Thanks for any help given.

Link to comment
https://forums.phpfreaks.com/topic/220753-time-formatting/
Share on other sites

To format the result, which I believe was the original question:

 

$minutes = floor($howlongleft / 60); // number of whole minutes left
$secs = sprintf('%02d', $howlongleft % 60); // remainder of time left (in seconds) divided by 60.
echo "$minutes:$secs";
?>

Link to comment
https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143358
Share on other sites

$timewaiting = time() + 160; // Waiting time. (2min)

if ((time()-$timewaiting) < time()){
$howlongleft = $timewaiting - time();

echo ("You must wait $howlongleft seconds.");
}

That only seems to echo 160.

Thanks for the reply though.

Because you got to add the time to like a database, because there you only add the time then check = only gives the time you gave.

Link to comment
https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143363
Share on other sites

To format the result, which I believe was the original question:

 

$minutes = floor($howlongleft / 60); // number of whole minutes left
$secs = sprintf('%02d', $howlongleft % 60); // remainder of time left (in seconds) divided by 60.
echo "$minutes:$secs";
?>

Yeah thanks, worked just how I wanted it :D.

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143364
Share on other sites

Archived

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

×
×
  • Create New...

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.