Parse string in HH.mm format to TimeSpan
string YourString = "01.35";
var hours = Int32.Parse(YourString.Split('.')[0]);
var minutes = Int32.Parse(YourString.Split('.')[1]);
var ts = new TimeSpan(hours, minutes, 0);
Updated answer:
Unfortunately .NET 3 does not allow custom TimeSpan
formats to be used, so you are left with doing something manually. I 'd just do the replace as you suggest.
Original answer (applies to .NET 4+ only):
Use TimeSpan.ParseExact
, specifying a custom format string:
var timeSpan = TimeSpan.ParseExact("11.35", "mm'.'ss", null);
Parse out the DateTime
and use its TimeOfDay
property which is a TimeSpan
structure:
string s = "17.34";
var ts = DateTime.ParseExact(s, "HH.mm", CultureInfo.InvariantCulture).TimeOfDay;