在 C# 中将字符串转换为日期时出现错误。错误是:
string is not valid datetime.
下面是我用来将字符串转换为日期时间的代码。
string[] DateFormat = { "dd-MM-yyyy", "dd/MM/yyyy", "MM-dd-yyyy", "MM/dd/yyyy" ,"dd-MMM-yy"};
VendorSinceDate = DateTime.ParseExact(dtresult.Rows[0]["VendorSinceDate"].ToString(),DateFormat,System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None);
//dtresult.Rows[0]["VendorSinceDate"].ToString()="06-Jun-12 12:00:00 AM";