C# json日期转换

时间:2022-02-25 08:24:50

#region 日期转换 reJson = Regex.Replace(reJson, @"\\/Date\((\d+)\)\\/", match => { DateTime datetime = new DateTime(1970, 1, 1); datetime = datetime.AddMilliseconds(long.Parse(match.Groups[1].Value)); datetime = datetime.ToLocalTime(); return datetime.ToString("yyyy-MM-dd"); }); #endregion

转换前:

{"iserror":"0","errmsg":"查询成功","data":[{"cardCTCC":"8924","cardBegin":"\/Date(1491926400000)\/","cardEnd":"\/Date(1523462400000)\/","isBegin":"已激活"}]}

转换后:

{"iserror":"0","errmsg":"查询成功","data":[{"cardCTCC":"8924","cardBegin":"2017-04-12","cardEnd":"2018-04-12","isBegin":"已激活"}]}