Parsing a Date Like “Wednesday 13th January 2010” with .NET

前端 未结 7 1767
孤城傲影
孤城傲影 2021-01-07 19:49

How can I convert the following strings to a System.DateTime object?

Wednesday 13th January 2010
Thursday 21st January 2010
Wednesday 3rd February 2010

7条回答
  •  我在风中等你
    2021-01-07 20:31

    Another approach.

    string sDate = "Wednesday 13th January 2010";
    string[] sFields = sDate.Split (' ');
    string day = sFields[1].Substring (0, (sFields[1].Length - 2));
    DateTime date = new DateTime (sFields[3], sFields[2], day);
    

提交回复
热议问题