处理C#中两个不同时区之间的时差 [英] Handling Time Differences between two different Time Zone in C#

查看:195
本文介绍了处理C#中两个不同时区之间的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在使用在线电子商务网站,目前正在寻找分析两个不同时区之间时差的方法会影响我们的Web应用程序。



这就是我正在使用的当前场景。



我们的服务器现在位于华盛顿,他们计划在未来几个月内搬到芝加哥。他们属于两个不同的时区,我必须对代码(C#)以及其他配置内容需要注意的差异方面进行分析



我的第一个问题是搜索代码并找出在C#中使用DateTime类型的所有网页/字段。



我不确定在这方面下一步该做什么。



你能指导一下这个场景要解决的所有方面吗?



我们非常感谢您的帮助,并提前感谢您的帮助。



谢谢,

布莱恩。

解决方案

我认为最好的办法总是在协调世界时中工作: http://en.wikipedia.org/wiki/UTC [ ^ ]。



这样,服务器端时间的任何问题都将被消除,因此,例如,您可以自由地重新定位任何对此功能部分没有任何问题的服务器。当地时间应仅出现在客户方,无论它们在何处。请参阅:

http://msdn.microsoft.com /en-us/library/system.datetime.utcnow.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.datetime.tolocaltime.aspx [ ^ ]。



-SA

Hello,

I'm working with an Online E-Commerce Web site and currently looking to do an analysis of how the time difference between two different time zones would affect our Web Application.

This is what is the current Scenario I'm working with.

"Our Servers are currently located in Washington now and they are planned to be moved to Chicago in next few months. They belong to two different time zones and I have to do the analysis of the difference aspects that would need to be taken care with respect to Code (C#) and as well as the other configuration stuffs"

My first take is to search the code and find out what are all the web pages/fields that uses the DateTime type in C#.

I'm not sure what to do next in this regard.

Can you please guide me as to what are all the aspects that to be addressed with respect to this scenario?

Your help is highly appreciated and Thanks in Advance for your help.

Thanks,
Bryan.

解决方案

I think the best approach is to always work in Coordinated Universal Time: http://en.wikipedia.org/wiki/UTC[^].

This way, any concerns of the server-side time will be eliminated, so, for example, you can freely relocate any of your servers having no problem with this part of functionality. The local time should appear only on client sides, not matter where they are. Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.utcnow.aspx[^],
http://msdn.microsoft.com/en-us/library/system.datetime.tolocaltime.aspx[^].

—SA


这篇关于处理C#中两个不同时区之间的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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