Hi,

I want to parse the time from a string in c#, something like,

TimeSpan a = new TimeSpan();
string pattern = @"^\d{1}:\d{1}@";
if ( dt.Rows[x][y].ToString() != "" && System.Text.RegularExpressions.Regex.IsMatch(dt.Rows[x][y].ToString(), pattern ) ) {
if ( !TimeSpan.TryParse(dt.Rows[x][y].ToString(),out a ) )
   {
      MessageBox.Show(b.ToString()); 
   }                           
}

So, if I have a string with 8:00 or 12:59 is valid. But if I have 13:00 or just a number like 8 an nothing else give to me an error. Any ideas?

DateTime.Parse("23:59:59", null, System.Globalization.DateTimeStyles.AssumeLocal);
DateTime.Parse("23:59:59", null, System.Globalization.DateTimeStyles.AssumeLocal);

Thanks for the idea. It worked out!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.