Parsing a Date with Month name to C# DateTime

前端 未结 2 1024
抹茶落季
抹茶落季 2020-12-18 01:56

I want to parse the following date format to a DateTime object in C#.

\"19 Aug 2010 17:48:35 GMT+00:00\"

How can I accomplish this?

2条回答
  •  星月不相逢
    2020-12-18 02:26

    I'd recommend using DateTime.ParseExact.

    DateTime.ParseExact(dateString, "dd MMM yyyy H:mm:ss \\G\\M\\Tzzz", System.Globalization.CultureInfo.InvariantCulture);
    

    As suggested in the comments below, System.Globalization.CultureInfo.CurrentCulture is a good thing to be aware of and use if you are doing a desktop application.

提交回复
热议问题