如何根据访问者的位置显示本地化时间? [英] How to display localized time, based on a visitor's location?

查看:32
本文介绍了如何根据访问者的位置显示本地化时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个网站,全世界的人们都可以使用它.网站上有一个聊天区,我们希望消息带有时间戳.我将每个消息的时间戳记存储在数据库中.

如何根据访问者的本地时间向访问者显示每条消息的正确时间.

我不想问用户他的时区.有没有办法仅使用PHP?如果不是,根据访问者的当前时间,使用javascript显示当前时间的方式是什么?

解决方案

您可以使用地理IP对用户的时区进行有根据的猜测

http://php.net/manual/en/book.geoip.php

或者您可以使用javascript:

http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/

We're developing a website, that will be used from people all over the world. There's a chat section in the website and we want the messages to appear with a timestamp. I'm storing in a database a timestamp for each message.

What is the way to show the right time for each message to visitor, based on his local time.

I don't want to ask the user for his timezone. Is there a way to do this, using only PHP? If not - what is the way to show the current time, based on the visitors' current time, using javascript?

解决方案

You can make a educated guess on the users timezone with geo IP

http://php.net/manual/en/book.geoip.php

Or you can use javascript:

http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/

这篇关于如何根据访问者的位置显示本地化时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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