This is from the .Net SDK:
The following sample demonstrates the Parse method.
string strMyDateTime = "2/16/1992 12:15:12";
// myDateTime gets Feburary 16, 1992, 12 hours, 15 min and 12 sec.
System.DateTime myDateTime =
System.DateTime.Parse(strMyDateTime);
System.IFormatProvider format =
new System.Globalization.CultureInfo("fr-FR", true);
// Reverse month and day to conform to a different format.
string strMyDateTimeFrench = " 16/02/1992 12:15:12";
// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec.
System.DateTime myDateTimeFrench =
System.DateTime.Parse(strMyDateTimeFrench,
format,
System.Globalization.
DateTimeStyles.NoCurrentDateDefault);
string[] expectedFormats = {"G", "g", "f" ,"F"};
// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec.
myDateTimeFrench =
System.DateTime.ParseExact(strMyDateTimeFrench,
expectedFormats,
format,
System.Globalization.
DateTimeStyles.AllowWhiteSpaces);
Note the expectedFormats array, just use your own formats (and since you're
not going to be using locale specific formats you can use
CultureInfo.InvariantCulture instead of the french used in the example. And
if you're going to use only one format you can even use the simpler
ParseExact overload, ParseExact(string, string, IFormatProvider).
I do agree that you can't do this with Parse and you have to use ParseExact
(but the example is from Parse).
Jerry