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

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.