using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.Json; using System.Threading.Tasks; namespace Shentun.Utilities { public class JsonDateTimeConverter : System.Text.Json.Serialization.JsonConverter { private readonly string _dateFormat; public JsonDateTimeConverter(string dateFormat) { _dateFormat = dateFormat; } public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return DateTime.ParseExact(reader.GetString(), _dateFormat, null); } public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) { writer.WriteStringValue(value.ToUniversalTime().ToString(_dateFormat)); } } }