tmcdonnell Posted March 1, 2011 Share Posted March 1, 2011 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 Quote Link to comment Share on other sites More sharing options...
jasonrichardsmith Posted March 1, 2011 Share Posted March 1, 2011 get timestamp for your day, using string to time. subtract current time. multiply results to get your answer. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted March 1, 2011 Share Posted March 1, 2011 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. Quote Link to comment Share on other sites More sharing options...
tmcdonnell Posted March 1, 2011 Author Share Posted March 1, 2011 Thanks PaulRyan, it is perfect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.