How to set client timezone equal to server timezone window .Net C # application

The client application receives data via a WebService from a remote server. The application is mostly written in the 1.1 Framework Windows Form.

All I want to do is set the Time Time client application timeout to the time specified by the TimeZone server so that any time date inconsistencies can be avoided.

For this I would like to know how to get the server timezone and set the client's timezone to be equal to the server.

+1


source to share


4 answers


If you're using UTC on both sides, you don't need to worry about the offsets being different. You can convert UTC dates to local time for display in the app.



+1


source


I don't know what kind of problem we had with a similar problem in our application. When sending date and time from server to client at different time intervals, when client receives date and time, it can convert it to local time. I couldn't find a solution for this in .net 1.1. But in .Net 2.0 on DateTime has a Kind property , and if you set it to Unspecified, the client does not convert the time it receives from the server to local time.



+1


source


David

I think the original question is about getting TimeZone information from the server. I have seen sometimes that you need to get TimeZOne information in order to keep your server and client in the same zone.

For example, if you have a device that syncs with the server, if you send deviec to another location where it syncs to the local server, you can set your device's timezone information to the local server's timezone.

In this situation, it is very important to set the TimeZone time zone for the server, otherwise your client will display different / source time zone times.

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

0


source


if you are using .NET Framework 3.5 you can use TimeZoneInfo class to get timezone 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

0


source







All Articles