C# to Convert String to DateTime

前端 未结 6 1922
北海茫月
北海茫月 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

    string input = "Mon Apr 22 07:56:21 +0000 2013";
    string format = "ffffd MMM dd HH:mm:ss +ffff yyyy";
    DateTime dt;
    if(DateTime.TryParseExact(input,format,  CultureInfo.InvariantCulture,
                DateTimeStyles.None,out dt))
    {
        // do something with dt
    }
    

提交回复
热议问题