if (h1 == '2' && h2 greater than '3')
If any character is invalid, this test is redundant at this point. It should be part of the initial
if
statement. Something like:
if ((h1 < '0' || h1 > '2') || (h2 < '0' || h2 > '9') || (m1 < '0' || m1 > '5') || (m2 < '0' || m2 > '9') || (h1 == '2' && h2 > '3'))
{
printf("The time is not in the format HH:MM.");
return 1;
}