Jump to content

Countdown timer help


tmcdonnell

Recommended Posts

Hi all,

 

I would like to create a timer showing a countdown from 0% to 100% (representing "power") ending at noon GMT on Sunday 4th September.

The countdown started a few weeks ago, hence as of 1pm GMT on Tuesday 1st March, the countdown should be at 15%

The "power" increases by 5% every 11 days so by my calculations, the percentage in our countdown should increase by 0.01% every 1900.8 seconds.

 

So, with this theory, how would I go about coding it?

 

I guess since I use GMT, I need to take a timestamp in GMT first, then calculate the difference between this and Sunday 4th September at 12.00pm.

 

I am not sure though which format of time/date is best to do the calculation. Would it be better to use Unix time?

 

Any help, suggestions and/or code is greatly appreciated.

 

 

Skulty

 

 

Link to comment
https://forums.phpfreaks.com/topic/229281-countdown-timer-help/
Share on other sites

Try something like the following...

<?PHP

  date_default_timezone_set('Europe/London');

  $endTime   = strtotime("12:00:00 4 SEPTEMBER 2011");
  $startTime = strtotime("00:00:00 4 FEBRUARY 2011");
  $thisTime  = time();

  $timeDiff  = ($endTime-$startTime);
  $timePast  = ($thisTime-$startTime);
  $timeLeft  = ($timeDiff-$timePast);

  $percentageDone = ($timePast/($timeDiff/100));
  $percentageLeft = ($timeLeft/($timeDiff/100));

  echo number_format($percentageDone,2).'% power';

?>

 

Just change the start and end times accordingly :)

 

Regards, PaulRyan.

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.