C# to Convert String to DateTime

前端 未结 6 1935
北海茫月
北海茫月 2020-12-21 11:59

How to convert the below string to DateTime in C#?

Mon Apr 22 07:56:21 +0000 2013

When i tried the code with

         


        
6条回答
  •  清酒与你
    2020-12-21 12:40

    Use DateTime.ParseExact like:

    string str = "Mon Apr 22 07:56:21 +0000 2013";
    DateTime dt = DateTime.ParseExact(str,
                                       "ffffd MMM d HH:mm:ss +0000 yyyy",
                                       CultureInfo.InvariantCulture);
    

提交回复
热议问题