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));
}
}
}