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
https://forums.phpfreaks.com/topic/209013-number-formating-for-time/
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);

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.