几段倒计时正计时计算宝宝生日等的代码示例

计算天数的一段代码:

<SCRIPT LANGUAGE="JavaScript">     
<!--     
var urodz = new Date("August 10,2009"); //August 16,2004 改成出生那天 英文的,按此格式来
var now = new Date();     
var ile = now.getTime() - urodz.getTime();     
var dni = Math.floor(ile / (1000 * 60 * 60 * 24));     
if (dni > 0)     
   document.write("<font color=ff6500><b>" + dni + "</b></font>days")     
else     
    document.write("This will happen in future");     
// --></SCRIPT>

一段精确时间正计时的代码:

<script type="text/javascript" language="javascript">
function thenceThen(timespan){
 var date1=new Date(timespan);
 var totalSecs=(new Date()-date1)/1000;
 var days=Math.floor(totalSecs/3600/24);
 var hours=Math.floor((totalSecs-days*24*3600)/3600);
 var mins=Math.floor((totalSecs-days*24*3600-hours*3600)/60);
 var secs=Math.floor((totalSecs-days*24*3600-hours*3600-mins*60));
 document.getElementById("thenceThen").innerText=timespan+"距今:"+days+"天"+hours+"小时"+mins+"分钟"+secs+"秒";
}
var clock;
window.onload=function(){
 clock=self.setInterval("thenceThen('2009/08/01')", 500);
}
</script>

一段简单的宝宝出生天数的计时代码:

<script language="JavaScript">
var urodz= new Date("11/16/2007");
var s="佳佳生于2009年08月10日,已经";
var now = new Date();
var ile = now.getTime() - urodz.getTime() ;
var dni = Math.floor(ile / (1000 * 60 * 60 * 24));
var dni2 = Math.floor(dni/365);
var dni3 = Math.floor(dni-dni2*365);
if (dni > 365)
document.write(""+s+""+dni2 +"岁零"+dni3 +"天")
else if (dni > 1)
document.write(""+s+""+dni +"天了")
else
document.write("您还没出生哦!");
</script>

又一段正计时的代码:

<script language="JavaScript" type="text/javascript">
<!--
now = new Date()
nowyear=now.getFullYear()
if(nowyear<2000)
nowyear=nowyear+1900
nowmonth=now.getMonth()+1
nowdate=now.getDate()
years=nowyear-2008                 
months=nowmonth-06               
dates=nowdate-28                  
if((years<0)||((years==0)&&(months<0))||((years==0)&&(months==0)&&(dates<=0)))
document.write("<span><font color=red>你的系统时钟好像不太对哦!</font></span>")
else {
if(dates<0) {
months=months-1
dates=dates+30
}
if(months<0) {
years=years-1
months=months+12
}
document.write("<span>本博客已开通")         
if (years>0) {
document.write(years)
document.write("年")
}
if(months>0) {
document.write(months)
document.write("个月")
}
if(((years>0)||(months>0))&&(dates>0))
document.write("零")
if(dates>0) {
document.write(dates)
document.write("天")
}
else
document.write("整")
document.write("</span>")
if((months==0)&&(dates==0)) {
document.write("<span>!<font color=red><b>")  
document.write(years)
document.write("周年快乐!")     
document.write("</b></font></span>")
}
}
//-->
</script>

一段倒计时代码:

<div id="TimeCounter"></div>
<SCRIPT language=javascript>
<!--
//document.write("");

function show_date_time(){
 window.setTimeout("show_date_time()", 1000);
 target=new Date("2009-9-1");
 today=new Date();
 timeold=(target.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);
 
  if (daysold<0) {
	document.getElementById("TimeCounter").innerHTML="逾期,倒计时已经失效";
}
 else{
 if (daysold<10) {daysold="0"+daysold}
 if (daysold<100) {daysold="0"+daysold}
 if (hrsold<10) {hrsold="0"+hrsold}
 if (minsold<10) {minsold="0"+minsold}
 if (seconds<10) {seconds="0"+seconds}
 if (daysold<3) {
 	document.getElementById("TimeCounter").innerHTML="<font color=red>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒</font>";
}
 else
 	document.getElementById("TimeCounter").innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";
}
}
show_date_time();
//-->
</SCRIPT>
点赞 (0)

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code