31 lines
823 B
C#
31 lines
823 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace HuanMeng.DotNetCore.Json
|
|
{
|
|
public class CustomDateTimeConverter : JsonConverter<DateTime>
|
|
{
|
|
private readonly string _format;
|
|
|
|
public CustomDateTimeConverter(string format)
|
|
{
|
|
_format = format;
|
|
}
|
|
|
|
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(_format));
|
|
}
|
|
}
|
|
}
|