本文目錄一覽:
高分求一段 PHP 實時顯示倒計時 代碼
div id=”time”span id=”liveclock”/span
script type=”text/javascript”
function YaoShuai_time()
{
var Digital=new Date();
var hours=Digital.getHours();
var minutes=Digital.getMinutes();
var seconds=Digital.getSeconds();
var year=Digital.getFullYear();
var month=Digital.getMonth()+1;
var day=Digital.getDate();
var modhour=23-hours;
var modminute=59-minutes;
var modsecond=60-seconds;
if(month=9) month=”0″+month;
if(day=9) day=”0″+day;
if(minutes=9) minutes=”0″+minutes;
if(seconds=9) seconds=”0″+seconds ;
myclock=”當前時間: “+year+”-“+month+”-“+day+” “+hours+”:”+minutes+”:”+seconds+”剩餘時間”+modhour+”:”+modminute+”:”+modsecond;
if(document.layers){
document.layers.liveclock.document.write(myclock);
document.layers.liveclock.document.close();
}else {
document.getElementById(‘liveclock’).innerHTML=myclock;
}
setTimeout(“YaoShuai_time()”,1000)
}
YaoShuai_time();
/script
/div
php時間倒計時問題
在創建拼團的時候可以記錄一下當前的時間,然後再用當前時間 + 24 小時, 得到結束時間,每次執行代碼在沒有人參加的情況下都將判斷時間有沒有超出,超出–拼團結束。至於一個倒計時的效果可以用javascript 來做。
求助PHP倒計時程序
php部分,記錄下提交訂單時的時間戳,並以保存在數據庫中;
$postdate = time();
當用戶再次執行操作的時候,判斷操是否在48小時內的有效操作;
只需要比較,用戶操作時的時間戳和提交訂單時間是否超過48小時即可;
$operatetime = time();
if( $operate – $postdate 48 ) {
echo “有效”;
}else {
echo “無效”;
}
根據你的提問,我已經回答完畢;但我覺得你的提問,可能不是想要這個答案;你可能需要的是,在頁面上顯示跳時,的這種倒計時效果;所以,我在補充一下;你覺得能用,你就用;
1.還是一樣,記錄提交訂單時間戳到數據庫 $postdate;
2.當用戶再次訪問時的時間戳$nowtime = time();
這裡可以通過這兩個值,可以計算出,離48小時還有多少秒;
$time = 48 * 3600 – ($nowtime – $postdate);
3.把$time傳遞給js; 採用 var t = ? echo $time ?;
4.寫一個顯示函數;function showtime;
5.每秒執行一次.
6.大概代碼
div id=”shower”/div
script type=”text/javascript”
var t = ? echo $time ?;
var int =self.setInterval(“showtime()”,1);
function showtime(){
var hh = t / 3600;
var mm = (t – hh * 3600)/60
var ss = t – hh * 3600 – mm * 60;
var stringhh = hh 10 ? ‘0’+hh : hh;
var stringmm = mm 10 ? ‘0’+mm : mm;
var stringss = ss 10 ? ‘0’+ss : ss;
document.getElementById(‘shower’).innerHTml = stringhh + stringmm + stringss;
t = t -1;
}
/script
求php倒計時代碼
下面的例子程序就可以:
div id=’r’0/div
script language=”javascript”
var x=20*60;
function shw()
{
document.getElementById(‘r’).innerHTML=’還剩下’+parseInt(x/60)+’分’+parseInt(x%60)+’秒’;
x–;
if (x0) {alert(‘時間到’);}
else setTimeout(‘shw();’,1000);
}
shw();
/script
補充:
時間到了自動提交表單,可以使用下面的代碼(替換上面測試裡面的alert):
document.form1.submit();
上面的form1是表單的名稱,例如:
form name=form1 …
用JavaScript或php怎麼寫一個倒計時時鐘啊
這個是JavaScript的
距離北京奧運會開幕還有
br
html
head
title倒計時測試/title
!–倒計時設置代碼–
script language=”JavaScript”
!– hide script from old browser
var DifferenceHour = -1
var DifferenceMinute = -1
var DifferenceSecond = -1
var Tday = new Date(“Aug 8, 2008 20:00:00”) //**倒計時時間點-注意格式
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000
function clock()
{
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var timevalue = “”+((hour 12) ? hour-12:hour)
timevalue +=((minute 10) ? “:0″:”:”)+minute
timevalue +=((second 10) ? “:0″:”:”)+second
timevalue +=((hour 12 ) ? ” PM”:” AM”)
// document.formnow.now.value = timevalue
var convertHour = DifferenceHour
var convertMinute = DifferenceMinute
var convertSecond = DifferenceSecond
var Diffms = Tday.getTime() – time.getTime()
DifferenceHour = Math.floor(Diffms / daysms)
Diffms -= DifferenceHour * daysms
DifferenceMinute = Math.floor(Diffms / hoursms)
Diffms -= DifferenceMinute * hoursms
DifferenceSecond = Math.floor(Diffms / Secondms)
Diffms -= DifferenceSecond * Secondms
var dSecs = Math.floor(Diffms / microsecond)
if(convertHour != DifferenceHour) document.formnow.dd.value=DifferenceHour
if(convertMinute != DifferenceMinute) document.formnow.hh.value=DifferenceMinute
if(convertSecond != DifferenceSecond) document.formnow.mm.value=DifferenceSecond
document.formnow.ss.value=dSecs
// document.formnow.Tnow.value= DifferenceHour DifferenceMinute + DifferenceSecond + dSecs
setTimeout(“clock()”,1000)
}
// end hiding —
/script
/head
!–BODY裡面的ONLOAD注意–
body onload=”clock();return true” text=”red”
!–實現顯示–
form name=”formnow”
input name=”dd” type=”text” style=”border:0;” size=2
天
input name=”hh” type=”text” style=”border:0;” size=2
小時
input name=”mm” type=”text” style=”border:0;” size=2
分
input name=”ss” type=”text” style=”border:0;” size=2
秒
/form
!–倒計時完畢–
這個是php的
?php
/**************************************
**功能:PHP實時倒計時
**創建日期:2009-2-26
**作者:潘繼強 panjeck@tom.com
**
***************************************/
//php的時間是以秒算。js的時間以毫秒算
date_default_timezone_set(“Asia/Hong_Kong”);//地區
//配置每天的活動時間段
$starttimestr = “09:00:00”;
$endtimestr = “18:30:00”;
$starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
$nowtime = time();
?
!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”
html xmlns=””
head
meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /
titlePHP實時倒計時!/title
script language=”JavaScript”
!– //
var EndTime=?=$endtime*1000?;
var NowTime = new Date();
//計算出服務器和客戶端的時間差。
var dTime = NowTime.getTime()-?=$nowtime*1000?;
var runtimes = 0;
function GetRTime(){
var NowTime = new Date();
var dTimeNew = NowTime.getTime()-?=$nowtime*1000?;
var dTimesM = Math.abs(Math.floor((dTimeNew-runtimes*1000-dTime)/1000));//客戶端時間和服務器當前時間的差
if (dTimesM1) {//如果用戶修改了客戶端時間,就重新load本頁
window.location.reload();
}
var nMS = EndTime – NowTime.getTime()+dTime;
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(“RemainH”).innerHTML=nH;
document.getElementById(“RemainM”).innerHTML=nM;
document.getElementById(“RemainS”).innerHTML=nS;
if(nMS5*59*1000nMS=5*60*1000)
{
alert(“還有最後五分鐘!”);
}
runtimes++;
setTimeout(“GetRTime()”,1000);
}
window.onload=GetRTime;
// —
/script
/head
body
h1strong id=”RemainH”XX/strong:strong id=”RemainM”XX/strong:strong id=”RemainS”XX/strong/h1
/body
/html
實例3:
思路不同,簡單多了.
?php
/**************************************
**功能:PHP實時倒計時
**創建日期:2009-2-26
**作者:潘繼強 panjeck@tom.com
**
***************************************/
//php的時間是以秒算。js的時間以毫秒算
date_default_timezone_set(“Asia/Hong_Kong”);//地區
//配置每天的活動時間段
$starttimestr = “09:00:00”;
$endtimestr = “13:50:00”;
$starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
$nowtime = time();
if ($nowtime$starttime){
die(“活動還沒開始,活動時間是:{$starttimestr}至{$endtimestr}”);
}
$lefttime = $endtime-$nowtime; //實際剩下的時間(秒)
?
!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”
html xmlns=””
head
meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /
titlePHP實時倒計時!/title
script language=”JavaScript”
!– //
var runtimes = 0;
function GetRTime(){
var nMS = ?=$lefttime?*1000-runtimes*1000;
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(“RemainH”).innerHTML=nH;
document.getElementById(“RemainM”).innerHTML=nM;
document.getElementById(“RemainS”).innerHTML=nS;
if(nMS5*59*1000nMS=5*60*1000)
{
alert(“還有最後五分鐘!”);
}
runtimes++;
setTimeout(“GetRTime()”,1000);
}
window.onload=GetRTime;
// —
/script
/head
body
h1strong id=”RemainH”XX/strong:strong id=”RemainM”XX/strong:strong id=”RemainS”XX/strong/h1
/body
/html
另外,樓下的那個冷笑天只是一個秒錶,不知道樓主要的是秒錶還是倒計時,要是還有什麼其他需要或者代碼看不懂的,m我
呵呵呵
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/308617.html