?
Solved

Getting TimeZone GMT + Hours value

Posted on 2007-10-02
7
Medium Priority
?
179 Views
Last Modified: 2013-11-07
Hi All,

I want a simple C# code that gets the hours difference in windows time zone ,, for example if time zone selected = GMT + 3 ,, i want the value of 3 returned.

Thanks,
0
Comment
Question by:Abu Hamdan
  • 5
  • 2
7 Comments
 
LVL 10

Expert Comment

by:dkloeck
ID: 19997141
TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.UtcNow).Hours
0
 
LVL 10

Accepted Solution

by:
dkloeck earned 2000 total points
ID: 19997160
Oops.. it would be: TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours

with DateTime.UtcNow you would always get 0
0
 
LVL 7

Author Comment

by:Abu Hamdan
ID: 19997165
Hi,

I used your code, but it returns zero all the time. Do u know why? even i changed the time zone still returns zero

    int hrsDiff = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.UtcNow).Hours;
    MessageBox.Show(hrsDiff.ToString());

Above my code
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Expert Comment

by:dkloeck
ID: 19997173
already answered :)
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 19997180
you are checking what the offset to your local time is. And it returns 0 with DateTime.UtcNow because you convert it to the utc time before checking.
0
 
LVL 7

Author Comment

by:Abu Hamdan
ID: 19997181
Thats was quick :) ,,, thanks
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 19997192
you are welcome ^_^
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question