You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
873 B
30 lines
873 B
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<DateTime>
|
|
{
|
|
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));
|
|
}
|
|
}
|
|
|
|
}
|