Have you ever had to deal with consumer and provider of webservices residing in different time zones and one of the exchanges between them has to do with DateTime? If you have, then you probably know the output of the following piece of code. If not, I think its a good thing to know.
Let’s say we have a server in NY hosting a web service exposing the following web methods:
public DateTime GetServerTime()
public DateTime GetClientTime(DateTime clientTime)
public string ReturnMyTime(DateTime clientTime)
The consumer of this Web service is in LA. We have a WSManager class which takes care of the communication with the web service. The consumer invokes the web services in the following way:
string serverTime = WSManager.GetServerTime().ToString();
string clientTime = WSManager.GetClientTime(DateTime.Now).ToString();
string clientTime = WSManager.ReturnMyTime(DateTime.Now);
Will there be any differences between the three strings? If yes, what will it be?
[Update]: Raymond talks about differences between Win32 and .NET’s way of dealing with TimeZones and Day light savings
[Update]: On a relevant note do you see any difference between the following two lines of code, where the attempt is to have a DateTime (dt1, dt2) in universal time following the statements:
DateTime dt1 = DateTime.UtcNow.AddDays(184)
DateTime dt2 =DateTime.Now.AddDays(184).ToUniversalTime().ToString()