rmh rmh - 5 months ago 40
C# Question

How to parse Timezone Offset string?

I retrieve a value from my database of a timeZone offset. The value that I get is in time.

For example, it could be

, etc.

How do I convert that to a double so I can do an
call on a

Answer Source

Use the TimeSpan.Parse method:

var time = "+7:30";
time = time.Replace("+", "");  // Remove the + if it is there.

var hours = TimeSpan.Parse(time).TotalHours;