You can solve this problem with a regular expression. The advantage of this approach is that you get built in validation if the user enters numbers that is not a valid time.
Expression
^((?<hour>[0-9])|(?<hour>[0-1][0-9]))(?<minute>[0-5][0-9])$
*
^ is the start anchor. It means that the regex engine starts at the beginning of the string
*
((?<hour>[0-9])|(?<hour>[0-1][0-9])) means either a single digit from 0-9 or two digits where the first has to be 0 or 1.
?<hour> is a named group and makes it easy to extract parts of the regex later.
*
(?<minute>[0-5][0-9]) means that two digit will be matched where the first has to be within the range 0-5 and the second 0-9 -> 00 - 59.
*
$ is the end anchor and it means that no unmatched characters can come at the end of the string.
The C# code is not very complicated.
Add this variable as a member of the class
private static Regex timeExpression = new Regex("^((?<hour>[0-9])|(?<hour>[0-1][0-9]))(?<minute>[0-5][0-9])$");
Then you can use this code
DateTime time;
string inputData = "110";
Match m = timeExpression.Match(inputData);
if (m.Success)
{
int hour = int.Parse(m.Groups["hour"].Value);
int minute = int.Parse(m.Groups["minute"].Value);
time = new DateTime(0, 0, 0, hour, minute, 0);
}
else
{
}
If you then want to present the time for the user you can do that in different ways using the DateTime.ToString() method.
time.ToString("hh:mm");
How you take care of AM and PM is a different question.
I forgot to add that it is good to have a regular expression tool so you can easily test how it works.
This is the one I use:
RegEx Tester[
^]