Example of how to use the second kill countdown function implemented by PHP + JS, and js example
The example in this article describes how to implement the countdown to the second kill of commodities in PHP + JS. We will share this with you for your reference. The details are as follows:
<? Php // php time is calculated in seconds. The js time is calculated in milliseconds as date_default_timezone_set ('prc'); // date_default_timezone_set ("Asia/Hong_Kong "); // region // configure the daily activity period $ starttimestr = "8:10:00"; $ endtimestr = "9:43:00"; $ starttime = strtotime ($ starttimestr ); $ endtime = strtotime ($ endtimestr); $ nowtime = time (); if ($ nowtime <$ starttime) {die ("activity hasn't started yet, activity time is: {$ starttimestr} to {$ endtimestr} ");} if ($ endtime >=$ nowtime) {$ lefttime = $ endtime-$ nowtime; // actual remaining Time (seconds)} else {$ lefttime = 0; die ("activity has ended! ") ;}?>
<Script language = "JavaScript"> var runtimes = 0; function GetRTime () {var nMS = <? Php echo $ lefttime;?> * 1000-runtimes * 1000; if (nMS> = 0) {var nD = Math. floor (nMS/(1000*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 ("And the 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 time operation skills for PHP, JS, javascript, Python, mysql, and other common languages. For your reference:
Unix timestamp Conversion Tool:
Http://tools.jb51.net/code/unixtime