using System.Text.Json; using System; using System.Text.Json.Serialization; namespace ProductionLineMonitor.Web.Converter { public class DateTimeConverter : JsonConverter { private readonly string _dateFormatString; public DateTimeConverter() { _dateFormatString = "yyyy-MM-dd HH:mm:ss"; } public DateTimeConverter(string dateFormatString) { _dateFormatString = dateFormatString; } public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return DateTime.Parse(reader.GetString()); } public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) { writer.WriteStringValue(value.ToString(_dateFormatString)); } } }