using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.Collections;

namespace HuaTong.General.Utility
{
    /// <summary>
    /// 处理js序列化时 datetime返回UTC格式的问题
    /// 使用特性标识: [JsonConverter(typeof(JsonDateTimeConverter))]
    /// </summary>
    public class JsonDateTimeConverter : DateTimeConverterBase
    {
        string _format = "yyyy-MM-dd HH:mm:ss";

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            DateTime date = new DateTime();
            DateTime.TryParse((string)reader.Value, out date);
            return date;
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var date = SysDateTime.MinDatetime;
            var flag = DateTime.TryParse(value.ToString(), out date);
            writer.WriteValue(date.ToString(_format));
        }
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-10-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2022-01-26
  • 2021-10-13
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案