json时间格式的互换
c#代码
public class DateTimeUtil { /// <summary> /// 把json的时间格式还原-服务端 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string Json2Com(string str) { str = Regex.Replace(str, @"\\/Date\((\d+)\)\\/", match => { DateTime dt = new DateTime(1970, 1, 1); dt = dt.AddMilliseconds(long.Parse(match.Groups[1].Value)); dt = dt.ToLocalTime(); return dt.ToString("yyyy-MM-dd HH:mm:ss"); }); return str; } }
javascript客户端代码:
function showDate(val) { if (val != null) { val = val.replace("\/Date(", ""); val = val.replace(")/", ""); dt = new Date(Number(val)); return dt.toLocaleString(); } else { return ""; } }