如何从客户端位置获取正确的时间到服务器

时间:2012-10-16 13:16:29

标签: java web-services web

我的客户遍布不同的国家。但是,我的服务器位于不同的国家/地区。然后在服务器上我怎样才能在我的客户端获得时间。我知道我可以使用脚本来获取客户机上的系统时间。但如果我的客户机器上的时间设置不正确,这将失败。

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

// if you try to print it, it will return something like:
// Sat Mar 21 2009 20:13:07 GMT-0400 (Eastern Daylight Time)
// This time comes from the user's machine.
var myDate = new Date();

//Pass myDate to the server by loading something with an ajax call
$(someSelector).load('serviceurl.com?d='+myDate)

使用服务器端脚本处理收到的数据为$ _GET ['d']

要检查时间是否正确,您可以使用trid派对服务,但这更有可能让您错误的数据,然后是客户端计算机上的系统时间。有关详细信息,请参阅此IP to location + local time?

相关问题