title: Convert string to DateTime Format - wrong format
body: <p>I really cannot make sense of why this does not want to work. I get an exception:</p>
  
  <blockquote>
    <p>String was not recognized as a valid DateTime. </p>
  </blockquote>
  
  <p>I am reading the string date from a file and looks like this <code>2/27/2014 10:10:55</code></p>
  
  <p>This method receives the filename and extrapolates the data I need (latitude, longitude, date)</p>
  
  <pre><code>public void ReadCsvFile(string filename)
  {
      var reader = new StreamReader(File.OpenRead(filename));
      gpsDataList = new List&lt;GpsFileClass&gt;();
      while(!reader.EndOfStream){
          var line = reader.ReadLine();
          var values = line.Split(',');
          if(values[2].Contains("A")){
              values[2] = values[2].Substring(0,values[2].IndexOf("A"));
              values[2].Replace("\"", "");
              values[2] = values[2].Trim(); 
          }
  
          if(values[2].Contains("P")){
              values[2] = values[2].Substring(0, values[2].IndexOf("P"));
              values[2].Replace("\"", "");
              values[2] = values[2].Trim(); 
          }
          gpsDataList.Add(new GpsFileClass(Convert.ToDouble(values[0]), Convert.ToDouble(values[1]), Convert.ToString(values[2])));
      }
  }
  </code></pre>
  
  <p>Once the I have the file data in a List&lt;> I want to do some date comparisons and calculations. But first; I try to convert the string data containing date information to datetime like this:</p>
  
  <pre><code>public void SaveFrameGpsCoordinate()
  {
      int listSize = gpsDataList.Count;
  
      DateTimeFormatInfo dateTimeFormatInfo = new DateTimeFormatInfo();
      dateTimeFormatInfo.ShortDatePattern = "dd-MM-yyyy HH:mm:ss";
      dateTimeFormatInfo.DateSeparator = "/";
  
      //DateTime tempDateA = DateTime.ParseExact(gpsDataList[0].timeCaptured, "dd/MM/yyyy HH:mm:ss",null);
      //DateTime tempDateB = DateTime.ParseExact(gpsDataList[lastRecordData].timeCaptured, "dd/MM/yyyy HH:mm:ss", null);
  
      DateTime tempDateA = Convert.ToDateTime(gpsDataList[0].timeCaptured.Replace("\"", ""), System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
      DateTime tempDateB = Convert.ToDateTime(gpsDataList[lastRecordData].timeCaptured.Replace("\"", ""), System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
  }
  </code></pre>
  
  <p>As you can see even ParseExact throws the same exception, I tried it (hence commented it out).</p>
  
  <p>There are a lot solutions for this kind of problem but non seem to work on mine. I get that DateTime by default uses en-US calture. But When I even when I change the culture to "af-ZA" I get the same exception.</p>
  
  <p>Please help.</p>