DateTimeOffsetUnixTimeSecondsConverter Class
A custom JSON converter for handling System.DateTimeOffset objects. Converts to and from Unix time, which is the number of seconds that have elapsed since 00:00
UTC on 1 January 1970.public class DateTimeOffsetUnixTimeSecondsConverter : System.Text.Json.Serialization.JsonConverter<System.DateTimeOffset>Inheritance System.Object → System.Text.Json.Serialization.JsonConverter → System.Text.Json.Serialization.JsonConverter<System.DateTimeOffset> → DateTimeOffsetUnixTimeSecondsConverter
Methods
DateTimeOffsetUnixTimeSecondsConverter.Read(Utf8JsonReader, Type, JsonSerializerOptions) Method
Reads and converts the JSON to a System.DateTimeOffset object.
public override System.DateTimeOffset Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);Parameters
reader System.Text.Json.Utf8JsonReader
The reader to read JSON from.
typeToConvert System.Type
The type of object to convert to.
options System.Text.Json.JsonSerializerOptions
Options for the serializer.
Returns
System.DateTimeOffset
A System.DateTimeOffset object.
DateTimeOffsetUnixTimeSecondsConverter.Write(Utf8JsonWriter, DateTimeOffset, JsonSerializerOptions) Method
Writes a System.DateTimeOffset object as a Unix time (number of seconds since Unix epoch) to JSON.
public override void Write(System.Text.Json.Utf8JsonWriter writer, System.DateTimeOffset value, System.Text.Json.JsonSerializerOptions options);Parameters
writer System.Text.Json.Utf8JsonWriter
The writer to write JSON to.
value System.DateTimeOffset
The System.DateTimeOffset value to write.
options System.Text.Json.JsonSerializerOptions
Options for the serializer.