• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2520
  • Last Modified:

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

0
uswebpro9
Asked:
uswebpro9
  • 2
1 Solution
 
DhaestCommented:
I don't see what's wrong with it.
Don't you get the result that you want ?
0
 
uswebpro9Author Commented:
This works fine:

 
 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 timeDiffUtcServer = TimeZone.CurrentTimeZone.GetUtcOffset(System.DateTime.Now);
        TimeSpan timeDiffUtcClient = clientZone.BaseUtcOffset;
 
        TimeSpan totalTimeDifference = timeDiffUtcClient.Subtract(timeDiffUtcServer);
 
        return totalTimeDifference.TotalMinutes;
    }

Open in new window

0
 
DhaestCommented:
I assume that this "problem" is solved ?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now