Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how we can implement the countdown timer in php
exemple:Auction end in: 5 days 5 hours 4 minutes 4 sec

thanks u please help me
Posted
Updated 29-Aug-13 7:05am
v2
Comments
ZurdoDev 29-Aug-13 13:17pm    
Use javascript. There are likely jquery timer plugins you could use.

1 solution

You can do it just by manipulating 2 integers, followed by dividing them out to give you the num of days, hours, mins, secs.

You'd just want to base both times - current and expiration, on the unix epoch.

Use the php function time() to get the time since the epoch. Pass this number to the javascript. Using javascript, get the elapsed time since the epoch, at the current time. Subtract 1 from the other, do some dividing and et voila! You've the time remaining.

Now, run the func to calculate the time remaining once every second, minute, whatever.
Without the timer part, this is how the forum is able to tell you that something was posted seconds, minutes, hours ago or tell you it was 'yesterday' etc, etc.

http://stackoverflow.com/questions/1090869/why-is-1-1-1970-the-epoch-time

Here's an exerpt from an old project I have.
PHP
function makeNiceTime($intTime)
{
     $curTime = time();
     $strTime = '';
     if ( ($curTime-$intTime) <  (60)) //(24*60*60))
     {
        $strTime = sprintf("%d seconds ago", $curTime-$intTime);
     }
     else if ( ($curTime-$intTime) <  (60*60)) //(24*60*60))
     {
        $strTime = sprintf("%d minutes ago", ($curTime-$intTime) / 60 );
     }
     else if ( ($curTime-$intTime) <  (60*60*24)) //(24*60*60))
     {
        $strTime = sprintf("%d hours ago", ($curTime-$intTime) / (60*60) );
     }
     else if ( ($curTime-$intTime) <  (60*60*24*7)) //(24*60*60))
     {
        $strTime = sprintf("%d days ago", ($curTime-$intTime) / (60*60*24) );
     }
     else
     {  // sample: "12.22 am Sat 21-Jul 2012"
        $strTime = date("g.i a D j-M Y", $intTime);
     }
     return $strTime;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900