根据不同国家的用户计算机时间在网站上显示日期/时间 [英] display date/time on website base on user computer time in different country

查看:50
本文介绍了根据不同国家的用户计算机时间在网站上显示日期/时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网站应用程序的聊天信使.对于我的概念,我避免使用时区.

I am developing a chatting messenger of website application. For my concept, I avoid to use timezone.

当用户发布消息时,我使用 php 获取我当前的服务器日期/时间并将其保存到数据库中.

When a user post a message, I use php to get my current server date/time and save it onto database.

要向用户显示所有消息的时间,我只需要找出服务器时间和用户系统时间之间的差异.假设不同的是 3 小时,我只需要使用 mysql 从数据库中检索记录的服务器时间,然后将其添加 3,例如:$message-time-display = $server-time-of-message-posted + $different.

To display the time of all messages to the user, I just need find out the different between server time and user's system time. Let's say the different is 3 hours, i just need use mysql to retrieve recorded server time from database then add it with 3, eg : $message-time-display = $server-time-of-message-posted + $different.

对于本方案,虽然用户的电脑时间可能不正确,但不会影响我数据库中保存的时间记录.并且当用户更正了他们的计算机的时间时,它会显示正确的时间.这个解决方案可靠吗?如果是这样,为什么没有人这样做?为什么这么多人使用 GMT 或时区?也许我错过了一些重要的问题?

For this solution, although the user's computer time may be incorrect, it will not effect the time records that saved on my database. And it will display the correct time when the users have corrected their computer's time. Is this solution is reliable? If so, why there is none of people doing this? Why so many people are using GMT or timezone thingy? Maybe I miss some important issue?

推荐答案

只要用户正确设置了时间,您的解决方案就应该有效.这实际上是唯一的问题.为什么你认为没有人这样做?我猜他们中的大多数人都这样做,只有懒惰的人依赖 GMT/EST 时间.

Your solution should work as long as the user has the time set correctly. That is the only problem actually. Why do you think no one is doing it ? I guess most of them do and only the lazy ones relies on GMT/EST times.

提示:我看到了在跟踪代码中发送的用户时间,例如 google 的分析 javascript,可能是为了计算您正在计算的差异;)

Hint: I saw the user time sent in tracking codes such as google's analytics javascript, probably for computing the difference you are taking about ;)

这篇关于根据不同国家的用户计算机时间在网站上显示日期/时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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