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));
            }
        }
    }
  • 相关阅读:
    js正则匹配
    包含HTML的字符串去掉HTML标签
    smart-table 服务端请求真分
    禁用H5 表单验证novalidate
    webpack
    linux 进程查看及杀死进程
    配置ca服务器和http,mail加密
    mysql权限
    mysql查询
    mysql储存引擎
  • 原文地址:https://www.cnblogs.com/password1/p/5870737.html
Copyright © 2011-2022 走看看