如何获取页面加载事件时服务器上的客户机机器时间

How to get Client machine time on server on pageload event

本文关键字:服务器 客户机 时间 机器 事件 加载 何获取 获取      更新时间:2023-09-26

我想在页面加载事件中使用客户端系统日期,我该怎么做呢?

由于这不是一个回复,所以请让我知道如何做。

谢谢

var a = "&date=" + (new Date().replace(/'s+/g, ""));

只需将a的值附加到返回到服务器的所有链接。在服务器端,您将看到HTTP请求中出现的日期时间

var currentDate = new Date()

currentDate对象将有以下方法:

getMonth()
getDate()
getFullYear()

这应该能满足你的需要。

编辑:

既然你在文章的标题中提到了时间,那么可能值得一提的是currentDate也有:

getHours()
getMinutes()

如果你想显示当前时间

编辑2:

绑定到页面加载

<script type="text/javascript">
  function buildDate() {
    var date = new Date();
    /*build date string here*/
  }
</script>
<body onload="buildDate()">
Other stuff here...
</body>