服务器和客户端之间的时区差异? [英] Timezone diff between server and client?

查看:402
本文介绍了服务器和客户端之间的时区差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:



服务器系统遍布全球。

客户端计算机上的网页正在请求数据。



问题:



如何知道任何服务器和任何客户机之间的时区偏移?



工作:



Scenario:

Servers systems are all over the world.
Web page on the client machine is requesting data.

Issue:

How to know the time zone offset between any server and any client machine?

Work:

var DocumentTime = new Date();
function GetTimeZoneOffset()
	{
		var nTime = DocumentTime.getTime();
		var sUrl = xxxPhpUrl + '?TimeZoneOffSet=' + nTime;
		if(window.XMLHttpRequest)
		{
			var xhr = new XMLHttpRequest();
			xhr.open("GET", sUrl, true);
			xhr.onreadystatechange = function()
			{
				if (xhr.readyState == 4)
				{}
			}
			xhr.timeout = 30000;
			xhr.ontimeout = TimeOut;
			xhr.send(null);
		}
		nNow = null;
		nTime = null;
		sUrl = null;
	}

<body  önload="GetTimeZoneOffset()"





PHP ::





PHP::

if (isset($_GET['TimeZoneOffSet']))
{
	$ClientTime = $_GET['TimeZoneOffSet'];
	$ServerTime = time();
	$ServerTime = $ServerTime*1000;
	$Diff = $ServerTime - $ClientTime;
	echo $Diff;
	echo " Server ";
	echo $ServerTime;
	echo " and client ";
	echo $ClientTime;
}





网页在服务器上发布时间戳到php(使用get date函数),php应该采用时间戳并给出网页时间戳和当地时间戳之间的差异。



输出:

相差几乎不是70000微秒。即使服务器时区在PST中,客户端在EST中。这是正确的吗?



我如何实现这一目标?



Webpage Posts a timestamp to the php on the server (using get date function) and php should take the timestamp and give difference between the webpage timestamp and its local timestamp.

Output:
The difference is hardly 70000 microseconds. even though the server timezone is in PST and client is in EST. Is this correct?

How do i achieve this?

推荐答案

_GET [' TimeZoneOffSet']))
{
_GET['TimeZoneOffSet'])) {


ClientTime =
ClientTime =


_GET [' timezoneoffset的'];
_GET['TimeZoneOffSet'];


这篇关于服务器和客户端之间的时区差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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