Ah, everyone missed the important bit, this is
being read from JSON. You need to deserialize to the correct object, the
DateTimeOffset Struct (System) | Microsoft Learn[
^].
Here is an example:
using Newtonsoft.Json;
string rawJson = File.ReadAllText("sample_date.json");
Result result = JsonConvert.DeserializeObject<Result>(rawJson);
Console.WriteLine($"Date: {result.Date}");
Console.ReadKey();
public class Result
{
[JsonProperty("date")]
public DateTimeOffset Date { get; set; }
}
and here is the output (en-AU):
Date: 30/03/2023 1:32:55 AM +00:00
and here is the sample JSON used:
{
"date": "2023-03-30T01:32:55.000Z"
}