I'm trying to extract string from regular expression and convert it to string and converting it to Timespan again.
static Regex myTimePattern = new Regex(@"((\d+)+(\:\d+))$");
static TimeSpan DurationTimespan(string s)
{
if (s == null) throw new ArgumentNullException("s");
Match m = myTimePattern.Match(s);
if (!m.Success) throw new ArgumentOutOfRangeException("s");
string hh = m.Groups[0].Value.PadRight(2, '0');
string mm = m.Groups[2].Value.PadRight(2, '0');
int hours = int.Parse(hh);
int minutes = int.Parse(mm);
if (minutes < 0 || minutes > 59) throw new ArgumentOutOfRangeException("s");
TimeSpan value = new TimeSpan(hours, minutes, 0);
return value;
}
string hh shows = "30:00" and mm shows: "30". The time in my textbox from which data is collected is : "01:30:00". Please help me find a way.