I retrieve a value from my database of a timeZone offset. The value that I get is in time.
For example, it could be "-5:00"
, "+7:30"
, "+3:00"
, etc.
How do I convert that to a double so I can do an AddHours()
call on a DateTime
object?
Use the TimeSpan.Parse method:
var time = "+7:30";
time = time.Replace("+", ""); // Remove the + if it is there.
var hours = TimeSpan.Parse(time).TotalHours;