Reputation: 1365
I would like to know how I can convert the timezone you get from
TimeZoneInfo.Local.BaseUtcOffset.TotalHours.ToString()
(in this case, the code entered would display a number -7, my timezone). The problem is that if I enclose that line of code with a Convert.ToDouble()
method, it gives an error because of the negative symbol. It wouldn't be a problem if the timezone I was in didn't have a negative symbol to it. Is there a way to get just the number and not the negative symbol? (I can figure out negative timzones later...)
Upvotes: 0
Views: 855
Reputation: 34846
Get the absolute value via the Math.Abs
method, like this:
int value = (int)Math.Abs(TimeZoneInfo.Local.BaseUtcOffset.TotalHours);
Note: This will make -7
return 7
.
Upvotes: 4