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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.