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
boolDetermines 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
TypeThe 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
doubleThe 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
reader
JsonReaderThe Newtonsoft.Json.JsonReader to read from.
objectType
TypeThe type of the object to convert.
existingValue
objectThe existing value of the object being read.
serializer
JsonSerializerThe 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
writer
JsonWriterThe Newtonsoft.Json.JsonWriter to write to.
value
objectThe value to convert.
serializer
JsonSerializerThe calling serializer.
Exceptions
- NotSupportedException
Always thrown as this converter does not support writing.