title: how to perform c# time validation in HHMMSS format
body: <p>Output of this code will always be false,even if I pass date in  correct format.Please help me...
  Here the 2 Parameters passed are time and format, ie("HHMMSS" format).</p>
  
  <pre><code>    static bool ValidateTime(string time, string format)
      {
          try
          {
              //time = time.Replace(":","");
              System.Globalization.DateTimeFormatInfo tinfo = new System.Globalization.DateTimeFormatInfo();
  
              tinfo.LongTimePattern = format;
  
              DateTime dt = DateTime.ParseExact(time, "format", tinfo);
              if (dt.Hour != null)
              {
  
              }
              return true;
          }
          catch (Exception e)
          {
  
              return false;
          }
      }
  </code></pre>