当前位置:首页 » 操作系统 » 倒计时源码

倒计时源码

发布时间: 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-05-08 04:40:40 浏览:550
万立存储介质 发布:2024-05-08 04:33:02 浏览:636
ftppro特效复制方法 发布:2024-05-08 04:06:05 浏览:927
平板电脑编译软件 发布:2024-05-08 04:05:46 浏览:478
荣耀v6平板扩展存储 发布:2024-05-08 03:41:12 浏览:423
安卓手机为什么半年一更新 发布:2024-05-08 03:36:52 浏览:661
存储设备报价 发布:2024-05-08 02:22:01 浏览:554
定步长的算法 发布:2024-05-08 02:16:18 浏览:110
怎么使用pe口袋服务器 发布:2024-05-08 02:02:18 浏览:471
xml数据库c 发布:2024-05-08 02:01:46 浏览:456