页面倒计时 实现

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


<title>My JSP 'MyJsp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>
<style>
div{background: url(11.jpg) bottom; }

</style>
<script language="javascript">
var s ="2010-08-27 04:30:00";   //指定时间
var endTime=  new Date(Date.parse(s.replace(/-/g,"/")));
var endTimeLong = endTime.getTime();
setTimeout("show_time()",1000);
function show_time()
{
var time_distance,str_time;
var int_day,int_hour,int_minute,int_second;
var time_now=new Date();
time_now=time_now.getTime(); 

time_distance=endTimeLong-time_now;
if(time_distance>0)
{
//取出间隔时间的天、小时、分,java中时间换成毫秒是按照1000*60*60*24这样的换算方式转的
int_day=Math.floor(time_distance/86400000)
time_distance-=int_day*86400000;
int_hour=Math.floor(time_distance/3600000)
time_distance-=int_hour*3600000;
int_minute=Math.floor(time_distance/60000)
time_distance-=int_minute*60000;
int_second=Math.floor(time_distance/1000)

if(int_hour<10)
int_hour="0"+int_hour;
if(int_minute<10)
int_minute="0"+int_minute;
if(int_second<10)
int_second="0"+int_second;
str_time="<font size='7'  face='黑体'><b>"+int_day+"天"+int_hour+"时"+int_minute+" 分"+int_second+"秒</b& gt;</font>";
timer.innerHTML=str_time;
setTimeout("show_time()",1000); //循环调用
}else
{
timer.innerHTML ="时间已过";
clearTimeout(timerID)
}
}
</script>

<body>
<form name="timeForm">
<table> <tr>
<input type="hidden" id="time_end" name="time_end" value="" />


<td width="314px" height="215px">
<div align="center"><font color="yellow" size="6">剩余时间</font><div id="timer"></div></div>
</td>
</tr>
</table>
</form>

</body>
</html>

你可能感兴趣的:(java,html,jsp)