5

如果我在 c#字符串中有这些通用sql 有效日期

(每个日期可以在内部以不同的顺序排列)例如:

01 feb 2010
feb 01 2010
2010 01 feb
...
...

我想将字符串日期转换为DateTime(c#)。(我希望能够转换上面列表中的每种格式)

虽然解析精确需要我3!组合,有没有更好的解决方案?

4

1 回答 1

2

我想我明白了... 在此处输入图像描述

string[] str = new[] { "01 feb 2010","feb 01 2010","2010 01 feb","2010 feb 01","feb 2010 01" };
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");                       
for (int i = 0; i < str.Length; i++)
{
    DateTime t = DateTime.Parse(str[i], culture);
    t.Dump();
}
于 2012-07-01T10:21:02.503 回答