The example of this article tells the PHP+JS implementation of the product seconds to kill countdown usage. Share to everyone for your reference, specific as follows:
the time of <?php//php is in seconds. JS time in milliseconds
date_default_timezone_set (' PRC ');
Date_default_timezone_set ("Asia/hong_kong");/
/region//Configure daily activity time period
$starttimestr = "2016-3-29 8:10:00";
$endtimestr = "2016-3-29 9:43:00";
$starttime = Strtotime ($STARTTIMESTR);
$endtime = Strtotime ($ENDTIMESTR);
$nowtime = time ();
if ($nowtime < $starttime) {
die ("activity has not yet started, activity time is: {$starttimestr} to {$endtimestr}");
}
if ($endtime >= $nowtime) {
$lefttime = $endtime-$nowtime;//The actual remaining time (seconds)
}else{
$lefttime =0;
Die ("Activity is over!") ");
}
? >
<script language= "JavaScript" > var runtimes = 0; function Getrtime () {var NMS = <?php echo $lefttime;?>*1000-runtimes*1000; if (nms>=0) {var nd=math.floor (1
000*60*60*24))%24;
var Nh=math.floor (nms/(1000*60*60))%24;
var Nm=math.floor (nms/(1000*60))% 60;
var ns=math.floor (nms/1000)% 60;
document.getElementById ("Remaind"). Innerhtml=nd;
document.getElementById ("Remainh"). Innerhtml=nh;
document.getElementById ("REMAINM"). innerhtml=nm;
document.getElementById ("remains"). Innerhtml=ns; if (nms==5*60*1000) {alert ("Last five minutes!")
");
}
runtimes++;
SetTimeout ("Getrtime ()", 1000);
} var Num = 0;
onload = function () {Refresh ();
SetInterval ("Refresh ();", 100);
Getrtime ();
function Refresh () {if (num<10) {document.getElementById ("Remainl"). InnerHTML = Num;
num = num + 1;
}else{num=0; } </script>
PS: This site also provides a UNIX timestamp conversion tool, which contains the PHP, JS, JavaScript, Python, MySQL and other common language time operation skills, provided to you for reference:
Unix timestamp (timestamp) conversion tool:
Http://tools.jb51.net/code/unixtime
More about PHP Interested readers can view the site topics: "PHP date and Time usage summary", "PHP Mathematical Calculation Skills Summary", "PHP Array" operation Skills Encyclopedia, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Regular Expression Usage summary, "Summary of PHP operations and operator usage", "PHP string (String) Usage summary" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.