Jump to content

Number formating for time


AirBoss36

Recommended Posts

Hi Folks,

 

I understand the basic math to accomplish what I want, at least I think I do :)  I would like to confirm my logic and I need help with the final output format.

 

I am coding a simple browser based, resource type of game.  The gamer will select a certain item to produce another item and it will take x time to do it.  Here is the basics of what I want, minus the coding to make it look pretty. 

 

How do I format $y to show HHH:MM:SS?

 


$complete = time() + $x;

// To show how much time is remaining until completion or complete

$y = $complete - time();

if $y > 0 {

echo $y;

}

else {

echo "complete";

}

 

 

Link to comment
Share on other sites

I tried that format but it didn't work as I wanted.  It seemed to add the time to the current time.

 

I did a quick coding to test, using a value of 10,800 for x to show 3 hours remaining, but it added 3 hours to the current time of 07:00 to echo a value of 10:00:00

 

Any other ideas?  Perhaps I coded wrong?  Here is what I used:

 


$x = 10855;

echo $x;

echo "<br>";

echo date("h:i:s",$x);

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.