Parse "ISO 8601 BASIC" string

  • Thread starter Thread starter tballard
  • Start date Start date
T

tballard

Guest
Hi,

How can I parse an "ISO 8601 BASIC" string or an "extended" string or a normal string using a single method?

Basically, 2020-02-03T00:00:00 is an "extended" string and "20200203T000000" is a "basic" string.

Also, where's the best place to ask questions about .NET Core?

I saw that in .NET Core 3.1, System.Text.Json, it's supposed to support "ISO 8601:-2019".

So I made below little simple program. It works with the dashes; throws an error without. So Really the question is multiple questions: how do I parse Dates and Times without Dashes or Colons in .NET or .NET Core; and where do we ask questions about .NET Core.

private class MyType
{
public DateTime D { get; set; }
}

static void Main(string[] args)
{
string text = @"{""D"":""2020-02-03""}";
var thing = JsonSerializer.Deserialize<MyType>(text);
Console.WriteLine(thing.D.ToString());
}

Continue reading...
 
Back
Top