Java从服务器上获取时间动态显示在jsp页面实现思路
2013-08-01 17:16
1011 查看
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.text.SimpleDateFormat;"%>
<%
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>
<base href="<%=basePath%>">
<title>My JSP 'index.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>
<body>
<%
Calendar rightNow = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
%>
<script language="javascript">
//从服务器上获取初始时间
var currentDate = new Date(<%=new java.util.Date().getTime()%>);
function run()
{
currentDate.setSeconds(currentDate.getSeconds()+1);
var time = "";
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1;
var day = currentDate.getDate();
var hour = currentDate.getHours();
var minute = currentDate.getMinutes();
var second = currentDate.getSeconds();
if(hour < 10){
time += "0" + hour;
}else{
time += hour;
}
time += ":";
if(minute < 10){
time += "0" + minute;
}else{
time += minute;
}
time += ":";
if(second < 10){
time += "0" + second;
}else{
time += second;
}
document.getElementById("dt").innerHTML = year+"年"+month+"月"+day+"日" + time;
}
window.setInterval("run();", 1000);
</script>
<div id="dt">自动显示时间。。。。</div>
</body>
</html>
相关文章推荐
- Java从服务器上获取时间动态显示在jsp页面实现思路
- Java从服务器上获取时间,动态在jsp页面显示
- Java从服务器上获取时间,动态在jsp页面显示
- Java从服务器上获取时间,动态在jsp页面显示
- js实现动态获取系统时间,显示到页面上
- js实现动态获取系统时间,显示到页面上
- jsp页面动态显示服务器时间
- jsp页面中,动态调用系统时间的实现
- [安卓] 9、线程、VIEW、消息实现从TCP服务器获取数据动态加载显示
- 在JSP页面中显示动态时间
- jsp动态显示服务器时间 和 客户端显示时间
- JAVA:用多线程实现时间的动态显示
- JSP中实现动态显示系统时间
- 在jsp页面中实现日期时间的显示
- 在JSP页面中通过JS动态显示时间程序
- Java实现时间动态显示方法汇总
- js实现 页面显示系统时间(中文显示星期)、动态倒计时页面跳转
- jsp页面显示动态时间
- JS实现HTML页面中动态显示当前时间完整示例
- javascript jsp页面动态显示系统时间 测试可用 多浏览器通过测试 (1)