主题:倒时间程序
看看哪有错误?
<%@ page language="java" import="java.util.*"%>
<html>
<head>
<title>倒计时牌</title>
<script language="jscript">
<!--
var DifferenceHour = -1;
var DifferenceMinute = -1;
var DifferenceSecond = -1;
//初始化时间,以用做比较.
var Tday = new Date("8/8,2008 20:08:08");
//一天的毫秒数
var daysms = 24 * 60 * 60 * 1000;
//一小时的毫秒数
var hoursms = 60 * 60 * 1000;
//一分钟的毫秒数
var Secondms = 60 * 1000;
//一秒的毫秒数
var microsecond = 1000;
//定义计算时间的函数
function clock()
{
var time = new Date();
var hour = time.getHours();
var minute = time.getMinutes();
var second = time.getSeconds();
//将二十四进制时间格式转换为十二进制
var timevalue = "" + ((hour > 12) ? hour - 12 : hour);
timevalue += ((minute < 10) ? ":0":":") + minute;
timevalue += ((second < 10) ? ":0":":") + second;
timevalue += ((hour < 12) ? "PM" : "AM");
//定义需要的时间变量
var convertHour = DifferenceHour;
var convertMinute = DifferenceMinute;
var convertSecond = DifferenceSecond;
var Diffms = Tday.getTime() - time.getTime();
//用Math对象的floor()方法对时间差取整
DifferenceHour = Math.floor(Diffms / daysms);
Diffms = DifferenceHour * daysms;
DifferenceMinute = Math.floor(Diffms / hoursms);
Diffms -= DifferenceMinute * hoursms;
DifferenceSecond = Math.floor(Diffms / Secondms);
Diffms -= DifferenceSecond * Secondms;
var dSecs = Math.floor(Diffms / microsecond);
if(convertHour != DifferenceHour)
document.formnow.dd.value = DifferenceHour;
if(convertMinute != DifferenceMinute)
document.formnow.hh.value = DifferenceMinute;
if(convertSecond != DifferenceSecond)
document.formnow.mm.value = DifferenceSecond;
document.formnow.ss.value = dSecs;
//document.formnow.Tnow.value = DifferenceHour + DifferenceMinute + DifferenceSecond + dSecs;
setTimeout("clock()",1000);
}
-->
</script>
</head>
<body onload = "clock();return true">
<form name="formnow">
距离奥运会还有:
<input type=text name=dd size=2>天
<input type=text name=hh size=2>小时
<input type=text name=mm size=2>分
<input type=text name=ss size=2>秒啦!
</form>
</body>
</html>
<%@ page language="java" import="java.util.*"%>
<html>
<head>
<title>倒计时牌</title>
<script language="jscript">
<!--
var DifferenceHour = -1;
var DifferenceMinute = -1;
var DifferenceSecond = -1;
//初始化时间,以用做比较.
var Tday = new Date("8/8,2008 20:08:08");
//一天的毫秒数
var daysms = 24 * 60 * 60 * 1000;
//一小时的毫秒数
var hoursms = 60 * 60 * 1000;
//一分钟的毫秒数
var Secondms = 60 * 1000;
//一秒的毫秒数
var microsecond = 1000;
//定义计算时间的函数
function clock()
{
var time = new Date();
var hour = time.getHours();
var minute = time.getMinutes();
var second = time.getSeconds();
//将二十四进制时间格式转换为十二进制
var timevalue = "" + ((hour > 12) ? hour - 12 : hour);
timevalue += ((minute < 10) ? ":0":":") + minute;
timevalue += ((second < 10) ? ":0":":") + second;
timevalue += ((hour < 12) ? "PM" : "AM");
//定义需要的时间变量
var convertHour = DifferenceHour;
var convertMinute = DifferenceMinute;
var convertSecond = DifferenceSecond;
var Diffms = Tday.getTime() - time.getTime();
//用Math对象的floor()方法对时间差取整
DifferenceHour = Math.floor(Diffms / daysms);
Diffms = DifferenceHour * daysms;
DifferenceMinute = Math.floor(Diffms / hoursms);
Diffms -= DifferenceMinute * hoursms;
DifferenceSecond = Math.floor(Diffms / Secondms);
Diffms -= DifferenceSecond * Secondms;
var dSecs = Math.floor(Diffms / microsecond);
if(convertHour != DifferenceHour)
document.formnow.dd.value = DifferenceHour;
if(convertMinute != DifferenceMinute)
document.formnow.hh.value = DifferenceMinute;
if(convertSecond != DifferenceSecond)
document.formnow.mm.value = DifferenceSecond;
document.formnow.ss.value = dSecs;
//document.formnow.Tnow.value = DifferenceHour + DifferenceMinute + DifferenceSecond + dSecs;
setTimeout("clock()",1000);
}
-->
</script>
</head>
<body onload = "clock();return true">
<form name="formnow">
距离奥运会还有:
<input type=text name=dd size=2>天
<input type=text name=hh size=2>小时
<input type=text name=mm size=2>分
<input type=text name=ss size=2>秒啦!
</form>
</body>
</html>