views:

1684

answers:

4

My Client Application Receives data through WebService from a Remote Server. The Application is basically written in 1.1 Framework Windows Form.

All I want to do is to set my Client App TimeZone equal to Server TimeZone so that any Date Time related discrepancies can be avoided.

For this I would like to know How to retrieve Server Time Zone and How to Set Client Time Zone equal to Server.

+1  A: 

If you use UTC on both sides you won't need to worry about the offsets being different. For display in your application, you can convert UTC dates to the local time.

DavGarcia
A: 

David,

I think original question is of getting TimeZone info from server. I have seen at times you need to get TimeZOne info to keep your server and client in same zone.

For example if you have device that synchronizes with the server if you take deviec to different location where it synchronizes local server the you may want to set your device timezone info to local server timezone.

In this situation it is highly important to set client TimeZone to Server timezone otherwise your client displays time of different / original timezone.

I think you can consider options like "DHCP Options", "NTP Server" but i am not aware of exact solution to this problem.

A: 

I don't know what exactly your issue is we had a similar issue in our app. When sending datetime from server to client in different timezones, when the client receives the datetime it could convert it to local time. I couldn't find a solution for this in .net 1.1. But in .Net 2.0 onwards DateTime has a property called Kind and if you set it's value to Unspecified the client doesn't convert the time it receives from the server to local time.

Satish
A: 

if you use .NET Framework 3.5 you could use TimeZoneInfo class to retrieve time zone information...

// Get time in local time zone 
DateTime thisTime = DateTime.Now;
Console.WriteLine("Time in {0} zone: {1}", TimeZoneInfo.Local.IsDaylightSavingTime(thisTime) ?
                  TimeZoneInfo.Local.DaylightName : TimeZoneInfo.Local.StandardName, thisTime);
Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(thisTime, TimeZoneInfo.Local));
// Get Tokyo Standard Time zone
TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
DateTime tstTime = TimeZoneInfo.ConvertTime(thisTime, TimeZoneInfo.Local, tst);      
Console.WriteLine("Time in {0} zone: {1}", TimeZoneInfo.Local.IsDaylightSavingTime(tstTime) ?
                  tst.DaylightName : tst.StandardName, tstTime);
Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(tstTime, tst));

TimeZoneInfo class

L. Cooper