Example of how to use the second kill countdown function implemented by PHP + JS, and js example

Source: Internet
Author: User

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

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.