在ASP页面中显示服务器没有客户端的时间 [英] Show time of server no client in asp page

查看:62
本文介绍了在ASP页面中显示服务器没有客户端的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个剧场表演时间.
但是我想显示用户连接到我的服务器时服务器PC的时间.下面的代码显示了客户端PC无服务器PC的时间.
我该怎么办?

I have this script for show time.
But I want to show time of server pc when a user connect to my server. Below code show time of client pc no server pc.
What should I do fot this?

<script type="text/javascript" language="JavaScript" >
   function mytime() {
   var now = new Date();
   var min = now.getMinutes();
   var hour = now.getHours();
   var sec = now.getSeconds();


   document.getElementById("time_b").innerHTML = (hour < 10 ? "0" + hour : hour) + ":" + (min < 10 ? "0" + min : min) + ":" + (sec < 10 ? "0" + sec : sec);

setTimeout("mytime()", 1000);
}
window.onload = mytime;
</script>

推荐答案

很显然,由于它是在客户端上运行的,因此无法获得服务器时间.要显示服务器时间,只需在后面的代码中设置标签或其他控件

Obviously this won''t work to get the server time since it is run on the client. To display the server time simply set a label, or some other control, in the code behind

Label time = new Label();
time.Text = DateTime.Now;
Controls.Add(time);


您没有提到页面是通过ASP.NET还是通过其他语言(如PHP,Ruby或Perl)呈现的,但如果是最简单的方法是从那里插入服务器日期/时间.如果您的网页未使用某种语言呈现,则可以使用 Ajax [服务器侧面包含 [^ ](SSI).
您也没有提到正在使用哪个Web服务器,但是SSI适用于所有主要的Web服务器,因此不会有任何问题.

还有问题吗?发表评论.

-MRB
You did not mention if the page is rendered via ASP.NET or by some other language as PHP, Ruby or Perl, but if it is the easiest way to go would be to insert the server date/time from there. If your page is not rendered by some language you could resort to Ajax[^] or Server Side Includes[^] (SSI).
You also did not mention which web server you are using, but SSI is available for all major web servers so that shouldn''t be any issue.

Still have questions? Leave a comment.

-MRB


这篇关于在ASP页面中显示服务器没有客户端的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆