Java-下面的jsp在myeclipse自带的web browser中显示的服务器时间为是么不变 ,而在浏览器中显示的时间会改变呢
<%@ page language="java" import="java.util.*" contentType="text/html; charset=GBK"%>
<html>
<head>
<title>一个典型的JSP页面</title>
</head>
<%
Date dnow=new Date();
int dhours=dnow.getHours();
int dminutes=dnow.getMinutes();
int dseconds=dnow.getSeconds();
out.println("服务器时间"+dhours+":"+dminutes+":"+dseconds);
%>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样子肯定不会变啦,只是获取到了执行的当前时间显示出来而已
需要定时刷新哦,亲
在 head 标签里面添加:
<meta http-equiv="refresh" content="1" />
世界就清净了,祝好
斑驳敬上
看看国家授时中心的JS代码吧:
居然是调用的,你干脆也这么做吧~~
要不你就用setTimeout的方式进行简单的周期执行吧 setTimeout(函数或命令,单位为毫秒的执行间隔周期),这样动态的更改时间即可
如果非要获取服务器的时间,还是使用JS Ajax查询服务器的时间吧~~
var swfCanvas = document.getElementById("swf_clock");
var swfCtrl = undefined;
function getSWFVersion(){
var n = navigator;
if (n.plugins && n.mimeTypes.length) {
var a = n.plugins["Shockwave Flash"];
if (a && a.description) {
return a.description.replace(/([a-zA-Z]|s)+/, "").replace(/(s)+r/, ".") + ".0";
}
}
else
if (window.ActiveXObject && !window.opera) {
for (var i = 10; i >= 2; i--) {
try {
var c = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + i);
if (c) {
return i + ".0.0";
break;
}
}
catch (e) {
}
}
}
}
function creatFlashfunction(id,url, width, height, fq){
var str = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width=" + width + " height=" + height + " name='"+fq+"' id='"+id+"'>";
str += "<param name='movie' value=" + url + ">";
str += "<param name=FlashVars value=" + fq + ">";
str += "<param name='menu' value='false'>";
str += "<param name='wmode' value='opaque'>";
str += "<param name='allowfullscreen' value='false'>";
str += "<param name='allowscriptaccess' value='always'>";
str += "<embed id='"+id+"_ff' FlashVars='"+fq+"' src='" + url + "' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=" + width + " height=" + height + " menu='false' allowfullscreen='false' allowscriptaccess='always' name='flashResult' wmode='opaque'/>";
str += "</object>";
swfCanvas.innerHTML = str;
}
function getSWF(movieName) {
var isIE = navigator.userAgent.indexOf('MSIE') != -1 && !window.opera;
if(isIE){
return document[movieName] || window[movieName];
}else {
return document[movieName+"_ff"] || window[movieName+"_ff"];
}
};
(function(){
var swfVer=getSWFVersion();
if(swfVer==undefined||swfVer.split(".")[0]<8){}
else {
swfCanvas.className = "swfBox";
creatFlashfunction("bd_swf_clock","http://www.baidu.com/swf/aladdin/clock/clock.swf","64px","64px","");
swfCtrl = getSWF("bd_swf_clock");
setTimeout(function(){
if (!swfLoaded) swfCanvas.style.display = "none";
},5000);
}
})();