PHP+JS implementation of product seconds Kill Countdown Usage Example _php tips

Source: Internet
Author: User
Tags php programming php regular expression time in milliseconds

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.