Class CloudflareDateTimeConverter
- Namespace
- Cloudflare.NET.Core.Json
- Assembly
- Cloudflare.NET.dll
Custom JSON converter for DateTime that handles Cloudflare's non-standard date formats.
Cloudflare APIs return dates in various formats that differ from ISO 8601:
"2025-12-07 05:59:36.458083+00"- Space instead of 'T', short timezone offset"2025-12-07T05:59:36Z"- Standard ISO 8601"2025-12-07T05:59:36+00:00"- ISO 8601 with full timezone
public sealed class CloudflareDateTimeConverter : JsonConverter<DateTime>
- Inheritance
-
CloudflareDateTimeConverter
- Inherited Members
Remarks
This converter attempts to parse dates using multiple formats, falling back to Parse(string) if specific formats don't match.
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type DateTime.
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- DateTime
The converted value.
Write(Utf8JsonWriter, DateTime, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueDateTimeThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.