在.NET 3.5的日期时间序列化的最佳实践 [英] Best practices for DateTime serialization in .NET 3.5

查看:223
本文介绍了在.NET 3.5的日期时间序列化的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此外,共有4年前,我跟着这个 MSDN文章建筑的DateTime使用的最佳实践.NET客户端上的.Net 1.1和ASMX Web服务(使用SQL 2000服务器作为后台)。我还记得序列化的问题,我曾与DateTime和测试工作需要对于不同的时区的服务器。

Some 4 years back, I followed this MSDN article for DateTime usage best practices for building a .Net client on .Net 1.1 and ASMX web services (with SQL 2000 server as the backend). I still remember the serialization issues I had with DateTime and the testing effort it took for servers in different time zones.

我的问题是:是否有一些新的技术,如WCF和SQL Server 2008类似的最佳实践文件,特别是增加了新的datetime类型的存储时区的感知信息

My questions is this: Is there a similar best practices document for some of the new technologies like WCF and SQL server 2008, especially with the addition of new datetime types for storing time zone aware info.

这是环境:

  1. 在SQL太平洋时间。
  2. 服务器2008
  3. 在不同的时区的Web服务层。
  4. 在客户端可以使用。NET 2.0或.Net 3.5在不同的时区。如果它很容易,我们可以强迫大家升级到.NET 3.5。 :)
  1. SQL server 2008 on Pacific Time.
  2. Web Services layer on a different time zone.
  3. Clients could be using .Net 2.0 or .Net 3.5 on different time zones. If it makes it easy, we can force everyone to upgrade to .Net 3.5. :)

什么好的建议/以在每一层用于数据类型的最佳实践?

Any good suggestions/best practices for the data types to be used in each layer?

推荐答案

我觉得这样做的最好的办法就是始终传递对象为UTC,并转换为当地时间的客户端。通过这样做,存在用于所有客户端的公共参考点。

I think the best way of doing this is to always pass the object as UTC, and convert to local time on the clients. By doing so, there is a common reference point for all clients.

要转换为UTC,调用ToUniversalTime DateTime对象上。然后,在客户端上,呼叫ToLocalTime得到它在它们的当前的时区。

To convert to UTC, call ToUniversalTime on the DateTime object. Then, on the clients, call ToLocalTime to get it in their current time zone.

这篇关于在.NET 3.5的日期时间序列化的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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