/// <summary> /// 格式化日期 /// </summary> /// <param name="foramt">格式化规则</param> /// <returns></returns> public JsonConverter DateForamt(string foramt) { Newtonsoft.Json.Converters.IsoDateTimeConverter dateConverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter(); //格式日期 dateConverter.DateTimeFormat = foramt; return dateConverter; }
//调用的时候 string json = Newtonsoft.Json.JsonConvert.SerializeObject(T, this.DateForamt("yyyy'-'MM'-'dd HH':'mm':'ss"));
方式二
IsoDateTimeConverter timeFormat = new IsoDateTimeConverter(); timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; Response.Write(JsonConvert.SerializeObject(bll.GetModelList(strWhere), Newtonsoft.Json.Formatting.Indented, timeFormat));