time - PHP Count Down Expiry Button or Link -


i'm trying create button or link expire after 1 hour.

i'm setting time visitor hit page cookie.

most of code examples have seen give time has passed , not time left.

example: link expire in 0 hours, 30, mins , 34 seconds

this rough code :

//setting cookie example setcookie('previous_time', time(), time()+3600*1);   $current_time = time(); $previous_time = $_cookie['previous_time'];  $time_diff = $current_time-$previous_time; 

this i'm stuck, have no idea how convert $time_diff timestamp format "expire in 0 hours, 30, mins , 34 seconds"

many thanks.

to format time difference, math, since $time_diff number of seconds between 2 times:

$hours    = floor( $time_diff / 3600); $minutes  = floor( ($time_diff / 60) % 60);  $seconds  = $time_diff % 60;  echo "$hours hours, $minutes minutes, $seconds seconds\n"; 

so, value of 20712 would produce :

5 hours, 45 minutes, 12 seconds  

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -