title: .NET: Why is TryParseExact failing on Hmm and Hmmss?
body: <p>I'm trying out the <code>DateTime.TryParseExact</code> method, and I have come over a case that I just don't get. I have some formats and some subjects to parse that each should match one of the formats perfectly:</p>
  
  <pre><code>var formats = new[]
       {
           "%H",
           "HH",
           "Hmm",
           "HHmm",
           "Hmmss",
           "HHmmss",
       };
  
  var subjects = new[]
       {
           "1",
           "12",
           "123",
           "1234",
           "12345",
           "123456",
       };
  </code></pre>
  
  <p>I then try to parse them all and print out the results:</p>
  
  <pre><code>foreach(var subject in subjects)
  {
      DateTime result;
      DateTime.TryParseExact(subject, formats, 
          CultureInfo.InvariantCulture, 
          DateTimeStyles.NoCurrentDateDefault,
          out result);
  
      Console.WriteLine("{0,-6} : {1}", 
          subject,
          result.ToString("T", CultureInfo.InvariantCulture));
  }
  </code></pre>
  
  <p>I get the following:</p>
  
  <pre><code>1      : 01:00:00
  12     : 12:00:00
  123    : 00:00:00
  1234   : 12:34:00
  12345  : 00:00:00
  123456 : 12:34:56
  </code></pre>
  
  <p>And to my question... why is it failing on 123 and 12345? Shouldn't those have become 01:23:00 and 01:23:45? What am I missing here? And how can I get it to work as I would expect it to?</p>
  
  <hr>
  
  <p><strong><em>Update:</strong> So, seems like we might have figured out why this is failing sort of. Seems like the <code>H</code> is actually grabbing two digits and then leaving just one for the <code>mm</code>, which would then fail. But, does anyone have a good idea on how I can change this code so that I would get the result I am looking for?</em></p>
  
  <p><strong><em>Another update:</strong> Think I've found a reasonable solution now. Added it as an answer. Will accept it in 2 days unless someone else come up with an even better one. Thanks for the help!</em></p>