JsonDateTimeConverter

Ecng.Serialization

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

Herda de: JsonConverter

Construtores

JsonDateTimeConverter
public JsonDateTimeConverter(bool isSeconds)
jsonDateTimeConverter = JsonDateTimeConverter(isSeconds)

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

isSeconds
Determines whether the Unix timestamp is in seconds (true) or another resolution (false).
JsonDateTimeConverter
public JsonDateTimeConverter()
jsonDateTimeConverter = JsonDateTimeConverter()

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

Métodos

CanConvert
public override bool CanConvert(Type objectType)
result = jsonDateTimeConverter.CanConvert(objectType)

Determines whether this converter can convert the specified object type.

objectType
The type of the object to check.

Retorna: true if the objectType is DateTime or Nullable; otherwise, false. Accepting the nullable form lets the converter be registered globally and still cover optional DateTime? members.

Convert
protected virtual DateTime Convert(double value)
result = jsonDateTimeConverter.Convert(value)

Converts the specified double value to a DateTime.

value
The double value representing the Unix timestamp.

Retorna: A DateTime corresponding to the Unix timestamp.

ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
result = jsonDateTimeConverter.ReadJson(reader, objectType, existingValue, serializer)

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

reader
The JsonReader to read from.
objectType
The type of the object to convert.
existingValue
The existing value of the object being read.
serializer
The calling serializer.

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

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

Writes the JSON representation of the object.

writer
The JsonWriter to write to.
value
The value to convert.
serializer
The calling serializer.