nodo de C# aquí. Una pregunta simple, pero mirando todo en línea, parece que estoy haciendo esto bien. Pero, ¿puede alguien decirme por qué este código no funcionaría:Parece que DateTime.TryParseExact no coincide con AM/PM con "tt"
string testDateString = "2/02/2011 3:04:01 PM";
string testFormat = "d/MM/yyyy h:mm:ss tt";
DateTime testDate = new DateTime();
DateTime.TryParseExact(testDateString, testFormat, null, 0, out testDate);
// Value of testDate is the default {1/01/0001 12:00:00 a.m.}
Pero la simple eliminación de la AM/PM partir de la fecha de cuerdas y el "tt" en el formato funciona como se esperaba?
string testDateString = "2/02/2011 3:04:01";
string testFormat = "d/MM/yyyy h:mm:ss";
DateTime testDate = new DateTime();
DateTime.TryParseExact(testDateString, testFormat, null, 0, out testDate);
// Value of testDate is the expected {2/02/2011 3:04:01 a.m.}
Parece para que funcione bien para mí ... – SwDevMan81
Se supone que debes prestar atención al valor de retorno de TryParseExact(). Tienes falso aquí. Usa ParseExact en su lugar, ahora obtienes una buena excepción. –