JavaScriptSerializer中日期序列化问题

js请求的json数据返回前台的DateTime 类型被替换成了:\/Date(1404098342309)\/。

这个1404098342309数值,是1970年1月1日(DateTime的最小值)到date实际表示的日期之差的总毫秒数。

解决方法:

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

 

参考链接:http://www.cnblogs.com/songxingzhu/p/3816309.html

posted @ 2015-05-11 13:23  talentzemin  阅读(231)  评论(0编辑  收藏  举报