當前位置:首頁 » 編程語言 » php計時

php計時

發布時間: 2022-01-08 09:18:50

⑴ 我在php中計算出了一個倒計時的值,怎樣用JS每隔1秒刷新出來到網頁上

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS實現倒計時(時、分,秒)</title>
<script language="javascript" type="text/javascript">
var interval = 1000;
function ShowCountDown(year,month,day,divname)
{ var now = new Date();
var endDate = new Date(year, month-1, day);
var leftTime=endDate.getTime()-now.getTime();
var leftsecond = parseInt(leftTime/1000); //var day1=parseInt(leftsecond/(24*60*60*6));
var day1=Math.floor(leftsecond/(60*60*24));
var hour=Math.floor((leftsecond-day1*24*60*60)/3600);
var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
var cc = document.getElementById(divname);
cc.innerHTML = "網路提示距離"+year+"年"+month+"月"+day+"日還有:"+day1+"天"+hour+"小時"+minute+"分"+second+"秒"; } window.setInterval(function(){ShowCountDown(2016,6,5,'divdown1');
}, interval);
</script>
</head>
<body>
<div id="divdown1"></div>
</body>
</html>
給你提供個思路

⑵ php計時器從09年12月04日開始到現在的代碼正計時

你是想實現什麼效果?如果是想計算多少天,用時間戳就行了。
所謂時間戳,自己網路去,懂了這東西以後神馬日期計算都很簡單。
首先用strtotime把2009-12-04轉換為時間戳格式:
strtotime("2009-12-04");
然後用time();獲取當前時間戳
剩下的就足夠簡單了,當前時間減去2009-12-04,得到的就是2009-12-04 00:00到當前時間經過了多少秒,然後做點相應換算就可以了
補充下你的問題吧,你想做什麼都不知道呢

⑶ php中怎樣實現倒計時功能

設置一個目標時間,然後取得當前時間,進行計算,得出結果.
<?php
header("Content-type: text/html; charset=gbk");
echo "<font color=red>2015年國慶節倒計時!</font>"."<p>";
$time1=strtotime(date("Y-m-d H:i:s")); //當前系統時間
$time2=strtotime("2015-10-01"); //放假時間
$time3=strtotime("2016-01-01");
$sub1=ceil(($time2-$time1)/3600);
$sub2=ceil(($time3-$time1)/86400);
$sub3=ceil(($time2-$time1)/86400);
echo "距離放假還有<font color=red>$sub1</font>小時!!"."<p>";
echo "距離放假還有<font color=red>$sub3</font>天!!"."<p>";
echo "距離2016年元旦還有<font color=red>$sub2</font>天!!";
?>

結果如下:
2015年國慶節倒計時!
距離放假還有1797小時!!距離放假還有75天!!距離2016年元旦還有167天!!

⑷ PHP怎麼製作計時器

計時器的運用在網頁製作中很普遍,其實計時器有很多做法,PHP加JS、JS加AJAX也可以控制實現。不是PHP可以單獨實現的,因為PHP是實現服務端的語言,沒有辦法去控制。以下實例就是製作計時器的代碼:

<SCRIPTlanguage=JAVASCRIPT>
vartimerID=null;
vartimerRunning=false;
functionstopclock()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning=false;
}
functionstartclock()
{
stopclock();
showtime();
}
functionshowtime()
{
varnow=newDate();
varhours=now.getHours();
varminutes=now.getMinutes();
varseconds=now.getSeconds()
vartimeValue=""+hours;
//定時初始化資料庫的代碼:
timeValue+=((minutes<10)?":0":":")+minutes
timeValue+=((seconds<10)?":0":":")+seconds
document.Calc.time.value=timeValue;
//
//andhaveaclockonthestatusbar:
//window.status=timeValue;
timerID=setTimeout("showtime()",1000);
timerRunning=true;
return'';
}</script>
客服端PHP+HTML代碼:
<html>
<head>
<METAHTTP-EQUIV="Refresh"Content="1;URL=test.php">
</head>
<body>
<?
echodate("Y年m月d日H時i分s秒");
?>
</body>
</html>

⑸ php計時器問題

還真有幾個問題…另外這個是訪問計數器吧
首先不應該直接試圖讀取,應該先判斷是否存在
fclose($f)應該改成fclose($sdcard)
$num++後面缺少了分號
還有$w漏寫了

應該是$w = fopen("test.txt","w");

以下是修正的代碼:
<?php
if (!file_exists("test.txt")){
echo"文件不存在!";
$num = 0;
}else{
$sdcard = fopen("test.txt","r");
$num = fgets($sdcard,10);
fclose ($sdcard);
}
$num++;
$w = fopen("test.txt","w");
fwrite ($w,$num);
fclose ($w);
echo $num;
?>

⑹ PHP網站計時器如何實現 - PHP進階討論

<?php
ignore_user_abort();//關閉瀏覽器仍然執行
set_time_limit(0);//讓程序一直執行下去
$interval=2;//每隔一定時間運行[秒]
do{
//要執行的代碼
sleep($interval);//等待時間,進行下一次操作。
}while(true);
exit();
?>

⑺ php循環倒計時的代碼

這個可能要配合子框架和JS的功能來實現.
思路是:
1. 在主框架頁面上,安排一個表單 + 一個文本框(設變數名為 end_time),用來設置時間(target 指向子框)(日期格式: 2009-05-28 12:00:00 )
2. 再插入一個對象用來顯示剩餘時間(可以是文本框,也可以是<span>標記,還可以是其它可以用JS替換內容的對象就可以了)(假設它的標記是<span id="timeout"></span>).
3. 在主框架上插入一子框架,子框架的源文件指向php文件
4. 在PHP源文件中插入適當代碼.代碼的作用主要分幾部分,
A.計算剩餘時間
B.用於更新主頁面的剩餘時間對象的JS代碼.
C.適當設置頁面刷新的時間(用JS或刷頁刷新代碼)

部分代碼:
1.主框架(index.php)
<form action="timer.php" method="post" name="form1" target="timerframe" id="form1">
<table border="0">
<tr>
<td>開始時間
<label></label></td>
<td><input name="end_time" type="text" id="end_time" value="<?php echo date("Y-m-d H:i:s");?>" /></td>
<td><label>
<input type="submit" name="Submit" value="提交" />
</label></td>
</tr>
</table>
<table width="400" border="0">
<tr>
<td> </td>
</tr>
<tr>
<td>離結束還有:<span class="STYLE1" id="timeout">aaaaa</span></td>
</tr>
</table>
</form>
<iframe name="timerframe" width="1" height="1"></iframe>

2.子框架(timer.php)
<body>
<?php
$endTime=strtotime($_REQUEST['end_time']); //將終止時間轉為nix_timestamp格式
$now=time(); //當前時間
//printf( "N:%s,\n<br>E:%s\n<br>",$now,$endTime);
if($now>=$endTime) //如果時間已過結束時間
{

?>
<script language="javascript">
var f=parent.document.getElementById("form1")
f.end_time.value='<?php echo date("Y-m-d H:i:s",$endTime+2*3600);?>'
f.submit()
</script>
<?php
exit;
}
$timeLeft=$endTime-$now; //計算剩餘的秒數,並轉換為對應的 時:分:秒 的格式
?>
<script language="javascript">
parent.document.getElementById("timeout").innerHTML='<?php echo date("H:i:s",$timeLeft-8*3600);?>'
function refresh()
{
var f=parent.document.getElementById("form1")
f.submit();
}
setTimeout("refresh()",5000)
</script>
</body>

⑻ 求一24小時倒計時代碼有開始時間,最好是PHP的

<DIV class=aoyun><FONT <p> <p><font size="3">倒計時距離XX還有:</font></p></FONT><SPAN id=span_dt_dt></SPAN>
<SCRIPT language=javascript>
<!--
//document.write("");
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("8/22/2008 16:00:00");//這個日期是可以修改的
today=new Date();
timeold=(BirthDay.getTime()-today.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
span_dt_dt.innerHTML="<align=center><p><font color=#A22900><p><font size=4>"+daysold+"天"+hrsold+"小時"+minsold+"分"+seconds+"秒"+"<br></font><br></font>" ;
}
show_date_time();
//-->
</SCRIPT></td>
</tr>
</table>
</div>
<br></div>
<div>

⑼ php在線考試系統計時和計分

呵呵,看懂了,我也是搞了好久才弄好這個,優考試在線考試系統

⑽ 高分求一段 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>

熱點內容
如何提高三星a7安卓版本 發布:2024-09-20 08:42:35 瀏覽:658
如何更換伺服器網站 發布:2024-09-20 08:42:34 瀏覽:305
子彈演算法 發布:2024-09-20 08:41:55 瀏覽:283
手機版網易我的世界伺服器推薦 發布:2024-09-20 08:41:52 瀏覽:811
安卓x7怎麼邊打游戲邊看視頻 發布:2024-09-20 08:41:52 瀏覽:157
sql資料庫安全 發布:2024-09-20 08:31:32 瀏覽:88
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:502
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:651
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:477
電腦主伺服器怎麼開機 發布:2024-09-20 07:19:07 瀏覽:728