求助:如何给这个计时器加上年月?

txwdcom 2004-10-15 09:03:08
<body>
<div id="oDiv"></div>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var timerID;
var timerRunning = false;
var today = 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("September , 9 2002 08:00");
enday.setYear("2002");
secsPerDay = 1000 ;
minPerDay = 60 * 1000 ;
hoursPerDay = 60 * 60 * 1000;
PerDay = 24 * 60 * 60 * 1000;
secsLeft = (today.getTime() - enday.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 = ((today.getTime() - enday.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 = ((today.getTime() - enday.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 = ((today.getTime() - enday.getTime()) / PerDay);
daysLeft = (daysLeft - 0.5);
daysRound = Math.round(daysLeft);
daysRemain = daysRound;
timeRemain = "从开学到现在已经过了 " + daysRemain + " 天 " + hoursRemain + " 小时 " + minRemain + " 分钟 " + secsRemain + " 秒";
document.all("oDiv").innerHTML = timeRemain;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
startclock();
</SCRIPT>
</body>
...全文
63 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
txwdcom 2004-10-26
  • 打赏
  • 举报
回复
那月怎么加啊?
cybernaute 2004-10-23
  • 打赏
  • 举报
回复
<body>
<div id="oDiv"></div>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var timerID;
var timerRunning = false;
var today = 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("September , 9 2002 08:00");
enday.setYear("2002");
secsPerDay = 1000 ;
minPerDay = 60 * 1000 ;
hoursPerDay = 60 * 60 * 1000;
PerDay = 24 * 60 * 60 * 1000;
secsLeft = (today.getTime() - enday.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 = ((today.getTime() - enday.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 = ((today.getTime() - enday.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);

yearsLeft = ((today.getTime() - enday.getTime()) / (365*PerDay));
yearsRound = Math.round(yearsLeft-0.5);

daysLeft = (((today.getTime() - enday.getTime()) - (yearsRound*365*PerDay)) / PerDay);
daysLeft = (daysLeft - 0.5);
daysRound = Math.round(daysLeft);
daysRemain = daysRound;
timeRemain = "从开学到现在已经过了 " + yearsRound + " 年 " + daysRemain + " 天 " + hoursRemain + " 小时 " + minRemain + " 分钟 " + secsRemain + " 秒";
document.all("oDiv").innerHTML = timeRemain;
timerID = setTimeout("showtime()",1000);
timerRunning = true;

}
startclock();
</SCRIPT>
</body>
txwdcom 2004-10-23
  • 打赏
  • 举报
回复
谁帮帮我啊
txwdcom 2004-10-19
  • 打赏
  • 举报
回复
不行啊
这个是显示当前时间的
ouyld 2004-10-16
  • 打赏
  • 举报
回复
var sj=new Date()
var nian=sj.getYear()
var yue=sj.getDay()
alert(js+yue)
相关推荐
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2004-10-15 09:03
社区公告
暂无公告