Best practices for DateTime serialization in .NET 3.5

Question :

Best practices for DateTime serialization in .NET 3.5,

Answer :

Some 4 years back, I followed 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.

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.

Read More  .NET Remoting Speed and VPNs

This is the environment:

  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?

,

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.

Read More  How do you retrieve selected text using Regex in C#?

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

That’s the answer Best practices for DateTime serialization in .NET 3.5, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you

Read More  How do you impersonate an Active Directory user in Powershell?