mirror of
https://github.com/snltty/linker.git
synced 2025-10-08 18:40:07 +08:00
20 lines
597 B
C#
20 lines
597 B
C#
using System;
|
|
using System.Text.Json.Serialization;
|
|
using System.Text.Json;
|
|
|
|
namespace Linker.Libs.JsonConverters
|
|
{
|
|
public sealed class DateTimeConverter : JsonConverter<DateTime>
|
|
{
|
|
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
return DateTime.Parse(s: reader.GetString());
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
|
{
|
|
writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
}
|
|
}
|
|
}
|