Table of Contents

Class DateTimeConverter

Namespace
Cuemon.Extensions.Text.Json.Converters
Assembly
Cuemon.Extensions.Text.Json.dll

Provides a DateTime converter that can be configured like the Newtonsoft.JSON equivalent.

public class DateTimeConverter : JsonConverter<DateTime>
Inheritance
DateTimeConverter
Inherited Members
Extension Methods

Constructors

DateTimeConverter(String, CultureInfo)

Initializes a new instance of the DateTimeConverter class.

public DateTimeConverter(string format = "O", CultureInfo provider = null)

Parameters

format String

A standard or custom date and time format string.

provider CultureInfo

An object that supplies culture-specific formatting information.

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to DateTime.

public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader

The Utf8JsonReader to read from.

typeToConvert Type

The Type being converted.

options JsonSerializerOptions

The JsonSerializerOptions being used.

Returns

DateTime

The converted value.

Write(Utf8JsonWriter, DateTime, JsonSerializerOptions)

Write the value as JSON.

public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The Utf8JsonWriter to write to.

value DateTime

The value to convert.

options JsonSerializerOptions

The JsonSerializerOptions being used.

See Also