zoukankan      html  css  js  c++  java
  • c# 处理js序列化时 datetime返回UTC格式的问题

    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));
            }
        }
    }
  • 相关阅读:
    php获取文件后缀名格式
    猴子分桃问题2
    猴子吃桃问题1
    判断字符串中字母出现的次数用分割法
    成绩表
    二维数组所有元素求和输出
    冒泡排序
    1.8作业
    1.8
    1.6
  • 原文地址:https://www.cnblogs.com/password1/p/5870737.html
Copyright © 2011-2022 走看看