如何处理每一个聊天消息时区 [英] How do I handle the timezones for every Chat message

查看:153
本文介绍了如何处理每一个聊天消息时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用ASP.NET的Web聊天应用程序。我有聊天系统消息发送,并回传至客户合作。但是有一些事情,我注意到,但从来没有想过它会成为一个问题。我来自英格兰和聊天应用程序是坐在在美国的服务器和注意到当消息显示的时间,次数均位于美国的时区。我怎么会去设置,将对应于用户的时区的时区。

I am creating a web chat application using ASP.NET. I have got the chat system to work as messages are sent and relayed back to the clients. But there was something I noticed but never thought it would be a problem. I am from England and the chat application is sitting on servers in America and noticed when the message displayed the time, the times were situated in American time zones. How would I go about setting the timezones that will correspond to the user's timezone.

推荐答案

在UTC中存储数据。总是。因此,而不是存储 GETDATE(),存储 GETUTCDATE()(或 SYSUTCDATETIME()在SQL Server 2008 +)。

Store your data in UTC. Always. So instead of storing GETDATE(), store GETUTCDATE() (or SYSUTCDATETIME() in SQL Server 2008+).

这使得它非常容易转换的所有的在聊天到任何时间段用户在,而且有大量的在ASP.NET设施,以帮助你完成这个转换时间,如果你不不想做的SQL。

This makes it very easy to convert all times in a chat to whatever time zone the user is in. And there are plenty of facilities in ASP.NET to help you with this conversion if you don't want to do it in SQL.

这篇关于如何处理每一个聊天消息时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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