Table of Contents

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

reader Utf8JsonReader

The reader.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

An 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

writer Utf8JsonWriter

The writer to write to.

value DateTime

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.