문제

If I have theses general sql valid dates in c# strings :

(each date can be in different order inside ) e.g. :

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

I want to convert a string date to DateTime(c#). ( i want the ability to convert every format from above list)

while parse exact requires me 3! combinations , is there any better solution ?

도움이 되었습니까?

해결책

I think i got it ... enter image description here

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();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top