Reputation: 131
So far I've tried this:
try
{
TimeSpan durtime = TimeSpan.Parse(timeDur.ToString());
}
catch (FormatException)
{
MessageBox.Show("Bad Format", timeDur.ToString());
}
timeDur
is a MaskedTextBox with a mask of type __:__
(Validating type DateTime).
When I try to convert the timedur
MaskedTextBox into a string format, it gives me an exception of type System.FormatException:
"The string was not recognized as a valid TimeSpan."
Upvotes: 0
Views: 2989
Reputation: 131
I honestly have no idea why it started working now but
etimeWHP1.Value = btimeWHP1.Value.Add(TimeSpan.Parse(timeDur.Text));
This solved my problem.
Upvotes: 0
Reputation: 631
Have you considered using a DateTimePicker with Format "Time"?
This way you don't have to worry about Culture specific formatting and so on.
Upvotes: 1