-1

I have the following date

string dateTimeText = @"Fri Feb 21 23:07:58 +0000 2020";

I want to parse it:

DateTime.ParseExact(dateTimeText, "D M dd HH:mm:ss +ssss yyyy", new CultureInfo("en-US"));

this implementation throws exception. Thanks

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
fatnjazzy
  • 6,070
  • 12
  • 57
  • 83
  • 1
    https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings. The 3 letter abreviation for day is [`ddd`](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings#dddSpecifier), and for mounth its [`MMM`](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings#MMM_Specifier) But what is *+ssss* suppose to be ? May be you mean fraction of seconf [`ffff`](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings#ffffSpecifier) or time zone ? – Drag and Drop Feb 26 '20 at 07:18
  • Does this answer your question? [Parse string to DateTime in C#](https://stackoverflow.com/questions/5366285/parse-string-to-datetime-in-c-sharp) – Drag and Drop Feb 26 '20 at 07:21
  • `"ddd MMM dd HH:mm:ss zzzz yyyy"` – Dmitry Bychenko Feb 26 '20 at 07:22
  • It does not matter how you shuffle your date input string the answer is still the same ParseExact + check the documentation for Custom format. You can use classical debug jutsu. By cutting your input string in half on a separator an try that part of parse exact to narrow down to the part you have issue with. – Drag and Drop Feb 26 '20 at 07:26

1 Answers1

1

Well, if +ssss (+0000) stands for TimeZone (so +0000 means GMT) the pattern is

  "ddd MMM dd HH:mm:ss zzzz yyyy"

I.E.

  string dateTimeText = "Fri Feb 21 23:07:58 +0000 2020";

  var result = DateTime.ParseExact(
      dateTimeText, 
    @"ddd MMM dd HH:mm:ss zzzz yyyy", 
      CultureInfo.GetCultureInfo("en-US")); 

In case +ssss and (an corresponding +0000) are fractions of seconds the pattern will be

   "ddd MMM dd HH:mm:ss' +'FFFF yyyy"
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215