當前位置:首頁 » 操作系統 » 倒計時源碼

倒計時源碼

發布時間: 2022-01-18 04:04:08

① 倒計時器代碼

程序設計思想:
(1)輸入目標時間,高考的年,月,日,時,分,秒
下面例子中簡寫成直接賦值。
(2)轉換成 struct tm
(3)再轉換成 time_t
(4) 獲當前時間 now = time (NULL);
(5)用difftime 計算時間差,送返 long double 秒
(6)把秒轉換成 日,時,分,秒
(7)循環 (下面例子中簡寫成 列印120次,每隔2秒左右打一次)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}

void main(){
time_t rawtime;
struct tm * target_time;
int d,h,m,s;
int k=0;
long double dif,r;
time_t now,t_end; // in sec

/* get current timeinfo and modify it to the user's choice */
time ( &rawtime );
target_time = localtime ( &rawtime );

// time struc and to time_t
target_time->tm_year = 2008 - 1900; //year - 1900
target_time->tm_mon= 7 - 1; // month - 1
target_time->tm_mday = 15 ; // day
target_time->tm_hour = 13 ; // hour
target_time->tm_min = 1 ;
target_time->tm_sec = 1 ;
t_end = mktime (target_time);
// printf("%s ",ctime(&t_end)); //print and check

while (k < 120)
{
now = time (NULL);
// printf("%s ",ctime(&now)); // print and check
dif = difftime (t_end,now); //double , time_t time_t
// printf( "%lf\n",dif);
d = (int) (dif / 86400.0);
r = dif - d * 86400.0;
h = (int) (r / 3600.0);
r = r - h * 3600.0;
m = (int) (r / 60.0);
r = r - m * 60.0;
s = (int) (r);
printf("%d--days %d--hours %d--min %d--sec\n",d,h,m,s);
(void) wait ( 2 ); // every 2 seconds print
k = k + 1;

};
}

② 求個html倒計時代碼

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="box">
還剩:
<label for="" id="hour">00</label>小時
<label for="" id="minute">00</label>分
<label for="" id="second">00</label>秒
</div>
<script type="text/javascript">
var o_b=document.getElementById("box");
//獲取界面標簽對象
var o_h=document.getElementById("hour");
var o_m=document.getElementById("minute");
var o_s=document.getElementById("second");
function showTime(){
var nowDate=new Date();
//把結束時間轉化為日期對象
console.log(nowDate)
var nowTime=nowDate.getTime();
var endDate=new Date("2019/01/20 00:00:00");
var endTime=endDate.getTime();
//距離結束時間剩餘的秒數
var diffTime=parseInt((endTime-nowTime)/1000);
console.log(diffTime)
if(diffTime<=0){
o_b.innerHTML="秒殺結束";
clearInterval(t);//清除定時器
}
//將剩餘時間(秒)轉換為時、分、秒
var hour=parseInt(diffTime/60/60);
var minute=parseInt(diffTime/60%60);
var second=diffTime%60;
if(hour<10){
hour="0"+hour;
}
if(minute<10){
minute="0"+minute;
}
if(second<10){
second="0"+second;
}
console.log(o_h);
console.log(o_m);
console.log(o_s);
o_h.innerHTML=hour;
o_m.innerHTML=minute;
o_s.innerHTML=second;
// setTimeout(showTime,1000);
}
showTime();
var t=setInterval(showTime,1000);
console.log(t);
</script>
</body>
</html>

③ 求一個24小時的倒計時html代碼

這個不是HTML代碼能實現的,一般網頁使用JS腳本!比如:<SCRIPT LANGUAGE="JavaScript">
<!--
var maxtime = 24*60*60
function CountDown(){
if(maxtime>=0){
hour = Math.floor(maxtime/3600);
minutes = Math.floor(maxtime/1440);
seconds = Math.floor(maxtime%60);
msg = "距離結束還有"+hour+"時"+minutes+"分"+seconds+"秒";
document.all["timer"].innerHTML=msg;
if(maxtime == 5*60) alert('注意,還有5分鍾!');
--maxtime;
}
else{
clearInterval(timer);
alert("時間到,結束!");
}
}
timer = setInterval("CountDown()",1000);
//-->
</SCRIPT>
<div id="timer" style="color:red" mce_style="color:red"></div>

④ 求 倒計時5秒顯示 代碼!

<html>
<head>
<script>

var i=5;
function sett()
{
document.getElementById(\"theDiv\").innerHTML=i;
i--;
if(i >= 0)
setTimeout(\"sett()\",1000);
}
</script>
</head>
<body onload=\"sett()\">
<div id=\"theDiv\"></div>
</body>
</html>

⑤ 倒計時html代碼

倒計時的html代碼:

<!DOCTYPEHTML>
<html>
<head>
<metacharset="utf-8">
<title>CSS3圓環倒計時-源碼搜藏網</title>
<style>
.pie{width:200px;height:200px;background-color:blue;border-radius:100px;position:absolute;}
.pie1{clip:rect(0px,200px,200px,100px);-o-transform:rotate(0deg);-moz-transform:rotate(0deg);-webkit-transform:rotate(0deg);background:-moz-radial-gradient(20%50%0deg,#333,#0000ff);background:-webkit-gradient(radial,100100,0,100100,110,from(#000),to(#0000ff));}
.pie2{clip:rect(0px,100px,200px,0px);-o-transform:rotate(0deg);-moz-transform:rotate(0deg);-webkit-transform:rotate(0deg);background:-moz-radial-gradient(80%50%0deg,#333,#0000ff);background:-webkit-gradient(radial,100100,0,100100,110,from(#000),to(#0000ff));}
.hold{width:200px;height:200px;position:absolute;z-index:1;}
.hold1{clip:rect(0px,200px,200px,100px);}
.hold2{clip:rect(0px,100px,200px,0px);}
.bg{width:200px;height:200px;background-color:red;border-radius:100px;position:absolute;box-shadow:0px0px8px#333;background:-moz-radial-gradient(0%50%0deg,#900,#ff0000);background:-webkit-gradient(radial,100100,0,100100,110,from(#900),to(#ff0000));}
.time{width:160px;height:160px;margin:20px0020px;background-color:#fff;border-radius:100px;position:absolute;z-index:1;box-shadow:0px0px8px#333inset;text-align:center;line-height:160px;font-family:"BookAntiqua",Palatino,serif;font-size:35px;font-weight:bold;text-shadow:1px1px3px#333;}
.timeem{background:#fff;position:absolute;top:62px;left:12px;height:18px;width:140px;opacity:0.4;}
</style>
</head>
<body>
<divclass="holdhold1">
<divclass="piepie1"></div>
</div>
<divclass="holdhold2">
<divclass="piepie2"></div>
</div>
<divclass="bg"></div>
<divclass="time"><span></span><em></em></div>
<scriptsrc="http://www.codefans.net/ajaxjs/jquery-1.6.2.min.js"></script>
<script>
i=0;
j=0;
count=0;
MM=4;
SS=59;
MS=9;
totle=(MM+1)*600;
d=180*(MM+1);
MM="0"+MM;
functionshowTime(){
totle=totle-1;
if(totle==0){
clearInterval(s);
clearInterval(t1);
clearInterval(t2);
$(".pie2").css("-o-transform","rotate("+d+"deg)");
$(".pie2").css("-moz-transform","rotate("+d+"deg)");
$(".pie2").css("-webkit-transform","rotate("+d+"deg)");
}else{
if(totle>0&&MS>0){
MS=MS-1;
if(MS<10){MS="0"+MS};
};
if(MS==0&&SS>0){
MS=10;
SS=SS-1;
if(SS<10){SS="0"+SS};
};
if(SS==0&&MM>0){
SS=60;
MM=MM-1;
if(MM<10){MM="0"+MM};
};
};
$(".timespan").html(MM+":"+SS+":"+MS);
};
s=setInterval("showTime()",100);
functionstart1(){
i=i+0.6;
count=count+1;
if(count==300){
count=0;
clearInterval(t1);
t2=setInterval("start2()",100);
};
$(".pie1").css("-o-transform","rotate("+i+"deg)");
$(".pie1").css("-moz-transform","rotate("+i+"deg)");
$(".pie1").css("-webkit-transform","rotate("+i+"deg)");
};
functionstart2(){
j=j+0.6;
count=count+1;
if(count==300){
count=0;
clearInterval(t2);
t1=setInterval("start1()",100);
};
$(".pie2").css("-o-transform","rotate("+j+"deg)");
$(".pie2").css("-moz-transform","rotate("+j+"deg)");
$(".pie2").css("-webkit-transform","rotate("+j+"deg)");
};
t1=setInterval("start1()",100);
</script>
<inputonclick="window.open('view-source:'+window.location.href)"type="button"value="查看源代碼"style="position:absolute;right:0;top:0;width:80px;height:30px;">
</body>
</html>

直接復制代碼,創建html文件,然後復制進去,就可以看到效果了。

⑥ 網頁倒計時代碼

完整的程序代碼如下:

<span id=tt></span>秒以後返回<a href=index.html>首頁</a>

<script type=text/javascript>
var t=5;
function w(){
tt.innerHTML=t;
t--;
if (t==0) location.href='index.html';
setTimeout("w();",1000);
}
w();
</script>

以上代碼測試通過,使用方法是保存為HTML文件,使用瀏覽器打開。

⑦ 求:一款倒計時代碼

<br>距離考試還有<br>
<span id="span_dt_dt" style='border:1px solid black;background-color:#FFFFFF' ></span>
<SCRIPT language=javascript>
<!--
//document.write("");function show_student163_time(){
window.setTimeout("show_student163_time()", 1000);
BirthDay=new Date("04-01-2005");//改成你的計時日期
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=daysold+"天"+hrsold+"小時"+minsold+"分"+seconds+"秒" ;

}
show_student163_time();
//-->
</SCRIPT>

⑧ wap倒計時源碼

做不出來的,倒計時要靠瀏覽器腳本,手機上可沒有JavaScript,也沒有別的腳本語言,用flash lite 可以,不過也不能嵌在wap里

⑨ html頁面的倒計時代碼。。。。急求!!!!

<br>倒計時已結束<br>
<span id="span_dt_dt" style='border:1px solid black;background-color:#FFFFFF' ></span>
<SCRIPT language=javascript>
<!--
//document.write("");
function show_time(){
window.setTimeout("show_time()", 1000);
BirthDay=new Date("00-00-0000");//改成你的計時日期
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=daysold+"天"+hrsold+"小時"+minsold+"分"+seconds+"秒" ;
}
show_time();
//-->
</SCRIPT>
修改成需要的時間段,直接嵌入就可以。

⑩ 時間倒計時代碼

這是用VB寫的,需在窗體上放一個label控制項,如果你要用到自己程序里,裡面還需加一些大小判斷,請自己完善:
Private Sub Timer1_Timer()
Dim aa As Date
Dim bb As Date
aa = Now '一般用當前時間就可以了
bb = CDate("2006-11-30 11:38:33") '將來的時間
Label1.Caption = Year(bb) - Year(aa) & "年" & Month(bb) - Month(aa) & "月" & Day(bb) - Day(aa) & "天" & Hour(bb) - Hour(aa) & "小時" & Minute(bb) - Minute(aa) & "分鍾" & Second(bb) - Second(aa) & "秒鍾"
End Sub

熱點內容
醫院新冠肺炎疫情防控演練腳本 發布:2024-04-27 04:04:45 瀏覽:652
天津智慧網關伺服器雲伺服器 發布:2024-04-27 03:56:51 瀏覽:422
移門製作下料尺寸演算法 發布:2024-04-27 03:15:02 瀏覽:641
c語言5常量 發布:2024-04-27 02:38:49 瀏覽:991
源碼怎麼搭建 發布:2024-04-27 02:33:44 瀏覽:97
java獲取參數 發布:2024-04-27 02:22:21 瀏覽:501
unixlinuxwindows 發布:2024-04-27 02:10:55 瀏覽:445
nginx禁止ip訪問網站 發布:2024-04-27 02:05:43 瀏覽:845
webrtc伺服器搭建哪家價格低 發布:2024-04-27 01:30:08 瀏覽:141
oracle資料庫無法啟動 發布:2024-04-27 01:29:20 瀏覽:613