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
isSecondsboolDetermines 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
objectTypeTypeThe type of the object to check.
Returns
- bool
trueif the objectType is DateTime; otherwise,false.
Convert(double)
Converts the specified double value to a DateTime.
protected virtual DateTime Convert(double value)
Parameters
valuedoubleThe double value representing the Unix timestamp.
Returns
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
readerJsonReaderThe Newtonsoft.Json.JsonReader to read from.
objectTypeTypeThe type of the object to convert.
existingValueobjectThe existing value of the object being read.
serializerJsonSerializerThe calling serializer.
Returns
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
writerJsonWriterThe Newtonsoft.Json.JsonWriter to write to.
valueobjectThe value to convert.
serializerJsonSerializerThe calling serializer.
Exceptions
- NotSupportedException
Always thrown as this converter does not support writing.