JsonDateTimeConverter
Provides a JSON converter for converting DateTime values from Unix timestamps.
Наследует: JsonConverter
Конструкторы
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).
public JsonDateTimeConverter()
jsonDateTimeConverter = JsonDateTimeConverter()
Initializes a new instance of the JsonDateTimeConverter class using seconds as the default resolution.
Методы
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.
Возвращает: 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.
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.
Возвращает: A DateTime corresponding to the Unix timestamp.
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.
Возвращает: The converted DateTime value or null if conversion is not possible.
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.