与用户本地日期时间一起保存日期时间问题 [英] Save datetime issue with users local datetime

查看:98
本文介绍了与用户本地日期时间一起保存日期时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上建立了聊天服务之类的功能,当用户发送消息或接收消息时,我会在发送或接收消息时为他显示消息.

I built something like chat service in a website, and when a user send a message or receive a message I show for him when the message sent or received.

我将所有消息保存在数据库中.

I save all messages in the DB.

现在问题出在:托管网站的服务器在美国,并且某些用户来自不同国家/地区,并具有不同的时区.

Now the problem came from: the server which hosts the website is in USA, and some users come from different countries, with different time zones.

因此,我该用户发送了一条消息,例如他在埃及,他会看到他的消息是在6个小时前发送的,而不是他刚发送的:)

So I the user sent a message and he was in Egypt for example, he will see that his message sent 6 hours ago not now as he just sent :)

我想知道诸如Facebook,Twitter和stackoverflow之类的网站如何解决这个问题.

I want to know how website such as facebook, twitter and stackoverflow solve this issue.

注意:
-我在注册时不会询问用户有关其时区或国家/地区的信息.
-我正在使用ASP.Net MVC.
-我正在使用timeago jquery插件来显示漂亮的格式化日期.

Notes:
- I am not asking the user about his timezone or country while registration.
- I am using ASP.Net MVC.
- I am using timeago jquery plugin to show nice formated dates.

推荐答案

我猜最好的方法是每当用户提交文本时从用户的PC收集DateTime值.

I'd guess the best way would be to collect a DateTime value from your user's PC whenever they submit text.

由此,您应该能够根据时差数确定它们所在的时区.

From that, you should be able to determine what time zone they are in based on the number of hours difference.

然后,每当您在应用程序中显示时间戳时,都应增加或减去小时数差异.

Then, whenever you display the time stamp in your application, add or subtract the number of hours difference.

这篇关于与用户本地日期时间一起保存日期时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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