Class DateTimeConverter
- Assembly
- Cuemon.Extensions.Text.Json.dll
Provides a DateTime converter that can be configured like the Newtonsoft.JSON equivalent.
public class DateTimeConverter : JsonConverter<DateTime>
- Inheritance
-
DateTimeConverter
- Inherited Members
- Extension Methods
Constructors
DateTimeConverter(String, CultureInfo)
Initializes a new instance of the DateTimeConverter class.
public DateTimeConverter(string format = "O", CultureInfo provider = null)
Parameters
format
StringA standard or custom date and time format string.
provider
CultureInfoAn object that supplies culture-specific formatting information.
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to DateTime.
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
reader
Utf8JsonReaderThe Utf8JsonReader to read from.
typeToConvert
TypeThe Type being converted.
options
JsonSerializerOptionsThe JsonSerializerOptions being used.
Returns
- DateTime
The converted value.
Write(Utf8JsonWriter, DateTime, JsonSerializerOptions)
Write the value as JSON.
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
Parameters
writer
Utf8JsonWriterThe Utf8JsonWriter to write to.
value
DateTimeThe value to convert.
options
JsonSerializerOptionsThe JsonSerializerOptions being used.