title: Creating DateTime object from string
body: <p>I currently am reading from a text file an assortment of data, and parsing out everything. One of the items being parsed out is a start time for an event in the format of:</p>
  
  <pre><code>yyMMddHHmm
  1306050232 
  </code></pre>
  
  <p>I then parse out to the following:</p>
  
  <pre><code>string year = "20" + time[0].ToString() + time[1].ToString();
  string month = time[2].ToString() + time[3].ToString();
  string day = time[4].ToString() + time[5].ToString();
  string hour = time[6].ToString() + time[7].ToString();
  string minute = time[8].ToString() + time[9].ToString();
  string ampm ="";
  int hourInt = Convert.ToInt32(hour);
  
  if (hourInt &lt;= 12)
  {
      time = month + "." + day + "." + year + "@" + hour + ":" + minute + " " + "AM";
      ampm= "AM";                         
  }
  else
  {
      hourInt = hourInt - 12;      
      time = month + "." + day + "." + year + "@" + hourInt.ToString() + ":" + minute + " " + "PM";
      ampm= "PM";  
  }
  </code></pre>
  
  <p>once these are parsed out, i combined the variables, and try to put it into a DateTime. </p>
  
  <pre><code>string tempStartTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + " " + ampm;
  
  string starttime = DateTime.ParseExact(tempStartTime, "yyyy-MM-dd HH:mm tt",null);
  </code></pre>
  
  <p>my issue is, I get a warning like this from the try catch:</p>
  
  <pre><code>System.FormatException: String was not recognized as a valid DateTime.
     at System.DateTime.ParseExact(String s, String format, IFormatProvider provider)
     at Project.GUI.parseSchedule(Int32 count) 
  </code></pre>
  
  <p>I don't understand why, or how to correctly do this. </p>
  
  <p>All I want is to take the start time from the file, convert it to a datetime object, and operate on it afterwards.</p>