当前位置: 代码迷 >> Web前端 >> 2011年[兔年]记时
  详细解决方案

2011年[兔年]记时

热度:622   发布时间:2012-10-09 10:21:45.0
2011年[兔年]倒计时
<html>
  <head>
    <title>2011年[兔年]倒计时</title>
  </head>
  
<body OnLoad="startclock()">
<center>	
<!----------------------------->
<!--               新年快到                                      -->
<!--               心情特好                                      -->
<!--               工作做完                                      -->
<!--               放假还早                                      -->
<!--               闲人无聊                                      -->
<!--               整理资料                                      -->
<!--               陈旧技术                                      -->
<!--               仅供参考                                      -->
<!--               若有疑问                                      -->
<!--               可以探讨                                      -->
<!--                                                             -->
<!--               QQ:297187963                                 -->
<!--               E-mail:weishaoxiang@163.com                  -->
<!----------------------------->


<!----------------------------->
<!--               以下是用于计算的脚本代码                      -->
<!----------------------------->	
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

/*****           设置 2011年[兔年]倒计时 日期                   *****/
/*****     2011年2月3日晚上0点0分0秒 辛卯年正月初一 星期四      *****/    
var byear = 2011 ;
var mm = 2 ;
var bday = 3 ;
var newHours = 0;
var newMinutes = 0;
var newSecond = 0;
/******************************************************************/
TMonth = new Array(
'January','February','March',
'April','May','June','July',
'August','September','October',
'November','December'
);
CurMonth = mm - 1;
var bmonth = TMonth[CurMonth];

var year = new Date();
var year2 = year.getYear();
var year3 = (year < 2000) ? year2 + 1900 : year2;

var timerID;
var timerRunning = false;
var today = new Date();
var startday = new Date();
var enday = new Date();
var secPerDay = 0;
var minPerDay = 0;
var hourPerDay = 0;
var secsLeft = 0;
var secsRound = 0;
var secsRemain = 0;
var minLeft = 0;
var minRound = 0;
var minRemain = 0;
var timeRemain = 0;

/*------------------------------------*/
function stopclock() {
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}

/*---------------------页面初始化跳用 函数--------------------------------*/
function startclock() {
stopclock();
showtime();
}
/*------------------------------------*/

//--------------------计算 倒计时 函数------------------------
function showtime() {
today = new Date();//创建当前时期变量
enday = new Date(""+bmonth+", "+bday+" "+year3+" 00:00");//获取  日期
enday.setYear(""+year3+"");
enday.setHours(newHours);
enday.setMinutes(newMinutes);
startday.setYear(""+byear+"");

secsPerDay = 1000 ;  //毫秒
minPerDay = 60 * 1000 ;//一分钟有多少毫秒
hoursPerDay = 60 * 60 * 1000;//一小时有多少毫秒
PerDay = 24 * 60 * 60 * 1000;//一天有多少毫秒

//-----------计算出  秒数-------------------------------------------------------
secsLeft = (enday.getTime() - today.getTime()) / minPerDay;
secsRound = Math.round(secsLeft);
secsRemain = secsLeft - secsRound;
secsRemain = (secsRemain < 0) ? 
secsRemain = 60 - ((secsRound - secsLeft) * 60) :
secsRemain = (secsLeft - secsRound) * 60;
secsRemain = Math.round(secsRemain);
//------------------------------------------

//-----------计算出  分钟数-----------------------------------------------------
minLeft = ((enday.getTime() - today.getTime()) / hoursPerDay);
minRound = Math.round(minLeft);
minRemain = minLeft - minRound;
minRemain = (minRemain < 0) ? 
minRemain = 60 - ((minRound - minLeft)  * 60) : 
minRemain =((minLeft - minRound) * 60);
minRemain = Math.round(minRemain - 0.495);
//------------------------------------------

//-----------计算出  小时数-----------------------------------------------------
hoursLeft = ((enday.getTime() - today.getTime()) / PerDay);
hoursRound = Math.round(hoursLeft);
hoursRemain = hoursLeft - hoursRound;
hoursRemain = (hoursRemain < 0) ? 
hoursRemain = 24 - ((hoursRound - hoursLeft)  * 24) :
hoursRemain = ((hoursLeft - hoursRound) * 24);
hoursRemain = Math.round(hoursRemain - 0.5);
//------------------------------------------

//-----------计算出  天数-------------------------------------------------------
daysLeft = (( enday.getTime() - today.getTime() ) / PerDay);
daysLeft = (daysLeft - 0.5);
daysRound = Math.round(daysLeft);
daysRemain = daysRound;

if (daysRemain == 1) day_rem = " 天 "
else day_rem = " 天 "
if (hoursRemain == 1) hour_rem = " 小时 "
else hour_rem = " 小时 "
if (minRemain == 1) min_rem = " 分钟 "
else min_rem = " 分钟 "
if (secsRemain == 1) sec_rem = " 秒"
else sec_rem = " 秒"

//---------完整的显示语句-------------------------------------------------------
timeRemain = " "+daysRemain + day_rem + hoursRemain + hour_rem + minRemain 
+ min_rem + secsRemain + sec_rem;
document.down.face.value = timeRemain;//给文本框传递数值

timerID = setTimeout("showtime()",1000);
timerRunning = true;
if (daysRemain < 0) year3 = year3 + 1
}

//  End -->
</script>	
<!----------------------------->
<!--               用于计算的脚本代码结束                          -->
<!----------------------------->


<!--------------------- 显示计算结果 ------------------------------------------>
<form name="down" onSubmit="0">
2011年[兔年]倒计时:<input type="text" name="face" size="32" value="新年快乐">
</form>

<!-- 第三种形式 -->
<div id="clock" ></div>
<SCRIPT language=Javascript1.2>
<!--
function show() {
  if(!document.layers && !document.all) return;
  var d = new Date();
  var iYear = d.getYear()
  var iMonth = d.getMonth()
  var iDay = d.getDate()
  var sWeek = d.getDay()
  var sHour  = d.getHours()
  var sMinute = d.getMinutes()
  var sSecond = d.getSeconds()
  if(sWeek == 0) sWeek = "<font color=#ffffff>星期天</font>";
  if(sWeek == 1) sWeek = "星期一";
  if(sWeek == 2) sWeek = "星期二";
  if(sWeek == 3) sWeek = "星期三";
  if(sWeek == 4) sWeek = "星期四";
  if(sWeek == 5) sWeek = "星期五";
  if(sWeek == 6) sWeek = "<font color=#ffffff>星期六</font>";
  if(sHour <= 9) sHour = "0" + sHour;
  if(sMinute <= 9) sMinute = "0" + sMinute;
  if(sSecond <= 9) sSecond = "0" + sSecond;
  sClock = "现在时间:" + iYear + "年" + (iMonth + 1) + "月" + iDay + "日 " + sWeek
    + " " + sHour + ":" + sMinute + ":" + sSecond;
  if(document.layers) {
    document.layers.clock.document.write(sClock);
    document.layers.clock.document.close();
  }
  else if(document.all)
    clock.innerHTML = sClock;
  setTimeout("show()", 1000);
}
show();
//-->
</SCRIPT>
<p><hr>

</center>
  </body>
</html>

?