北京<第29届>奥运会开幕日期:2008年8月8日晚上8点8分 戊子年七月初八星期五
你想知道离北京 奥运会开幕式还有多少天吗?
把下面的代码保存为 xiaoxiang.html 网页文件运行就可看到了。
<!-- 北京奥运倒计时 -->
<!-- 把此代码保存为 xiaoxiang.html 文件,即可看到效果。-->
<!-- 制作者: 逍湘 -->
<!-- QQ:297187963 -->
<!-- E-mail:tylz7758@136.com -->
<!-- MSN:tylz7758@msn.com -->
<html>
<head>
<title>北京奥运倒计时</title>
</head>
<body OnLoad="startclock()">
<center>
北京<第29届>奥运会开幕日期:2008年8月8日晚上8点8分 戊子年七月初八星期五
<!----------------------------------------------------------------->
<!-- 以下是用于计算的脚本代码 -->
<!----------------------------------------------------------------->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
/***** 获取 北京 第29届 奥运会 开幕日期 *****/
/***** 2008年8月8日晚上8点8分 戊子年七月初八星期五 *****/
var byear = 2008 ;
var mm = 8 ;
var bday = 8 ;
/******************************************************************/
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();
}
/*--------------------------------------------------------------------------------------------------*/
//--------------------计算 2008年8月8日晚上8点8分 北京 第29届 奥运会的倒计时 函数------------------------
function showtime() {
today = new Date();//创建当前时期变量
enday = new Date(""+bmonth+", "+bday+" "+year3+" 00:00");//获取 第29届 奥运会 日期
enday.setYear(""+year3+"");
enday.setHours(20);
enday.setMinutes(8);
//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">
北京奥运倒计时:<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>
posted on 2007-11-21 20:42
逍湘 阅读(106)
评论(0) 编辑 收藏