Table of Contents

Class JsonDateTimeConverter

Namespace
Ecng.Serialization
Assembly
Ecng.Serialization.dll

Provides a JSON converter for converting DateTime values from Unix timestamps.

public class JsonDateTimeConverter : JsonConverter
Inheritance
JsonDateTimeConverter
Derived
Extension Methods

Constructors

JsonDateTimeConverter()

Initializes a new instance of the JsonDateTimeConverter class using seconds as the default resolution.

public JsonDateTimeConverter()

JsonDateTimeConverter(bool)

Provides a JSON converter for converting DateTime values from Unix timestamps.

public JsonDateTimeConverter(bool isSeconds)

Parameters

isSeconds bool

Determines whether the Unix timestamp is in seconds (true) or another resolution (false).

Methods

CanConvert(Type)

Determines whether this converter can convert the specified object type.

public override bool CanConvert(Type objectType)

Parameters

objectType Type

The type of the object to check.

Returns

bool

true if the objectType is DateTime; otherwise, false.

Convert(double)

Converts the specified double value to a DateTime.

protected virtual DateTime Convert(double value)

Parameters

value double

The double value representing the Unix timestamp.

Returns

DateTime

A DateTime corresponding to the Unix timestamp.

ReadJson(JsonReader, Type, object, JsonSerializer)

Reads the JSON representation of the object and converts it to a DateTime.

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)

Parameters

reader JsonReader

The Newtonsoft.Json.JsonReader to read from.

objectType Type

The type of the object to convert.

existingValue object

The existing value of the object being read.

serializer JsonSerializer

The calling serializer.

Returns

object

The converted DateTime value or null if conversion is not possible.

Exceptions

Newtonsoft.Json.JsonReaderException

Thrown when an error occurs during conversion.

WriteJson(JsonWriter, object, JsonSerializer)

Writes the JSON representation of the object. This method is not supported.

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)

Parameters

writer JsonWriter

The Newtonsoft.Json.JsonWriter to write to.

value object

The value to convert.

serializer JsonSerializer

The calling serializer.

Exceptions

NotSupportedException

Always thrown as this converter does not support writing.