-2

In .NET Core C#, how do I parse this Date string: 'Jun 3, 2021 4:36:56 PM EDT'

Tried this with Culture en-US, and it does not work:

DateTime.ParseExact("Jun 3, 2021 4:36:56 PM EDT", "MMM dd, yyyy hh:mm:ss tt K", CultureInfo.CurrentCulture);

Thanks, Jim

  • 2
    What do you mean by 'parse'? What are you trying to get/end up with? Could it be on [this](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) page? – wazz Jun 05 '21 at 00:36

1 Answers1

-1

I believe there's no support for TZ abbreviations of that sort, they are generally a mess. You could fix it by replacing "EDT" with "-04", though, something like:

var date = DateTime.ParseExact("Jun 3, 2021 4:36:56 PM EDT".Replace("EDT", "-04"), "MMM d, yyyy h:mm:ss tt zz", CultureInfo.InvariantCulture);

I also changed your dd to d, and hh to h. You can refer to the docs for more info on custom date/time formats. Also, here's a relevant question with some alternatives.