ASP+JS获取并实时显示服务器时间的代码

5 篇文章 0 订阅

第一种代码:

<html>
<head> 
<script language=javascript type="text/javascript"> 
//特别注明:北京时间是格林尼治标准时加八小时,因此用的起始时间也是从八点起算的 
var secondServer = <%=DateDiff("s", "1970-01-01 08:00:00", Now())%>; 
var secondClient = parseInt(new Date().getTime()/1000); 
var secondSub = secondServer - secondClient; //两端时间秒差 
function meizzTime(n) 

var mei = new Date(); 
mei.setTime(mei.getTime() + n*1000); //得到一个新的时间 
var h = (mei.getHours() > 9) ? mei.getHours() : "0" + mei.getHours(); 
var m = (mei.getMinutes() > 9) ? mei.getMinutes() : "0" + mei.getMinutes(); 
var s = (mei.getSeconds() > 9) ? mei.getSeconds() : "0" + mei.getSeconds(); 
document.meizz.clock.value ="【"+ h +":"+ m +":"+ s +"】"; 
setTimeout("meizzTime(secondSub)", 1000); 

</script> 
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'> 
<meta http-equiv="refresh" content="1000"> 
<title>javascript + asp 获取并实时显示服务器时间</title> 
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<style type="text/css">
<!--
.form {
FONT-FAMILY:verdana,Arial, Helvetica;
FONT-SIZE: 9pt; color:#000000;
HEIGHT: 18px;
line-height:14px;
background:none;
border: none;
}
-->
</style>
</head> 
<body onLoad="meizzTime(secondSub)">
<form name="meizz">
<input name="clock" size="12" class="form">
</form> 
</body>
</html>

  另一种代码:

<html>
<head> 
<script language=javascript type="text/javascript"> 
//特别注明:北京时间是格林尼治标准时加八小时,因此用的起始时间也是从八点起算的 
var secondServer = <%=DateDiff("s", "1970-01-01 08:00:00", Now())%>; 
var secondClient = parseInt(new Date().getTime()/1000); 
var secondSub = secondServer - secondClient; //两端时间秒差 
//星期函数
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i]
}
function meizzTime(n) 

var mei = new Date(); 
mei.setTime(mei.getTime() + n*1000); //得到一个新的时间 
var y = mei.getYear();//年
var t = mei.getMonth()+1;//月分需加1
var d = mei.getDate();//日
var w = new initArray(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六"); 
var z = w[mei.getDay()+1]//星期
var h = (mei.getHours() > 9) ? mei.getHours() : "0" + mei.getHours(); //时
var m = (mei.getMinutes() > 9) ? mei.getMinutes() : "0" + mei.getMinutes(); //分
var s = (mei.getSeconds() > 9) ? mei.getSeconds() : "0" + mei.getSeconds(); //秒
document.meizz.clock.value = y +" 年 "+ t +" 月 "+ d +" 日 " + z +" "+ h +":"+ m +":"+ s; //显示年月日和时间
setTimeout("meizzTime(secondSub)", 1000); 

</script> 
<meta http-equiv=’Content-Type’ content=’text/html; charset=gb2312’> 
<meta http-equiv="refresh" content="1000"> 
<title>javascript + asp 获取并实时显示服务器时间</title> 
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<style type="text/css">
<!--
.form {
FONT-FAMILY:verdana,Arial, Helvetica;
FONT-SIZE: 9pt; color:#000000;
HEIGHT: 18px;
line-height:14px;
background:none;
border: none;
}
-->
</style>
</head> 
<body onLoad="meizzTime(secondSub)">
<form name="meizz">
<input name="clock" size="100" class="form">
</form> 
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值