日期:2014-05-16  浏览次数:20427 次

js动态显示当前日期和时间

<%@ 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>刷新页面</title>
??<script>
???function show(){
???var date = new Date(); //日期对象
???var now = "";
???now = date.getFullYear()+"年"; //读英文就行了
???now = now + (date.getMonth()+1)+"月"; //取月的时候取的是当前月-1 如果想取当前月+1就可以了
???now = now + date.getDate()+"日";
???now = now + date.getHours()+"时";
???now = now + date.getMinutes()+"分";
???now = now + date.getSeconds()+"秒";
???document.getElementById("nowDiv").innerHTML = now; //div的html是now这个字符串
???setTimeout("show()",1000); //设置过1000毫秒就是1秒,调用show方法
???}
?</script>
</head>
?<body onload="show();"><!-- 网页加载时调用一次 以后就自动调用了-->


<div id="nowDiv"></div>
</body>
?
</html>

?

?

?

<%-- 用于自动刷新页面,解决session过期的问题 --%>
?<iframe id="refresh" name="refresh" src="${pageContext.request.contextPath }/administrator/refresh.jsp" height="0" width="0"></iframe>

?

<%@ 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>刷新页面</title>
????? <meta http-equiv="Refresh" content="60;url=refresh.jsp">
</head>
? <body> <!-- 网页加载时调用一次 以后就自动调用了-->
? </body>
</html>