Link to home
Start Free TrialLog in
Avatar of uswebpro9
uswebpro9Flag for Czechia

asked on

Get Time difference between 2 TimeZones

Hello,
I am trying to get the time difference between the server and the client.
Is this the best way to do it? I think my "TimeSpan totalTimeDifference" part is not right.

thanks
private double GetServerClientTimeDiff(string ClientTimeZoneId)
    {
        // Get the local time zone and the current local time and year.
        TimeZoneInfo clientZone = TimeZoneInfo.FindSystemTimeZoneById(ClientTimeZoneId);
 
        // What is the total difference between server and clients in minutes
        TimeSpan totalTimeDifference = TimeZone.CurrentTimeZone.GetUtcOffset(System.DateTime.Now).Add(clientZone.BaseUtcOffset);
 
        return totalTimeDifference.TotalMinutes;
    }

Open in new window

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

I don't see what's wrong with it.
Don't you get the result that you want ?
ASKER CERTIFIED SOLUTION
Avatar of uswebpro9
uswebpro9
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I assume that this "problem" is solved ?