主要站点如何检测时区? [英] How are major sites detecting timezone?

查看:96
本文介绍了主要站点如何检测时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook,myspace,MSN,craigslist;所有检测时区并正确显示时间和日期,而无需提交表格或重新加载页面。

Facebook, myspace, MSN, craigslist; all detect timezone and show times and dates correctly without ever submitting a form or reloading a page.

他们是如何做到的?我有一个非常大的网站,人们发布需要显示正确时间的文章(根据时区上传至下午3点或下午6点)。

How do they do it? I have a pretty large site and have people publishing articles which need to display correct times (uploaded 3pm or 6pm depending on timezone).

预加载器? JavaScript的?加载页面并重新加载?我的网站目前有人进入该网站,并在第一次进入时通过javascript重新加载页面,其中包含其时区的更新信息。然而,这是一个非常讨厌的事情,我正在寻找另一种选择。我知道在加载时我可以发出一个ajax请求然后让它更新整个站点的所有内容,并为用户提供正确的时区但是如果我必须单击返回,或者重新加载它询问我是否要再次发送信息这也很糟糕。那么他们是怎么做到的?

Preloaders? Javascript? Loading the page and reloading it? My site currently has the person enter the site and upon first entry it reloads the page with updated information of their timezone through javascript. This is however a pretty annoying thing and am looking for another alternative. I know that upon loading I can send out an ajax request and then have it update everything throughout the site with the correct timezone for the user BUT if I have to click back, or reload it asks if I'd like to send the information again which is also bad. So how do they do it?

我正在玩Facebook,改变我在本地机器上的位置,它似乎每5分钟左右更新一次。

I was playing around with Facebook, changing my location on my local machine and it seemed to update the timezone every 5 minutes or so.

我是php,基于zend-framework。

I am php, zend-framework based.

推荐答案

那里是没有时区请求标题,或类似的东西,所以,你不能用PHP

there is no "timezone" request header, or something like that, so, you can't with php

但是使用javascript你可以得到客户端的时区偏移量,然后你可以发一个xmlhttp请求发送信息到php

but with javascript you can get the timezone offset of the client, then you could make a xmlhttp request to send informations to php

看到这个: http://www.pageloom.com/automatic-timezone-detection-with-javascript

非常简单!

希望这有助于

这篇关于主要站点如何检测时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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