日常开发AJAX请求.NET服务器端Json序列化一个DateTime对象的结果是一个字符串,如 '/Date(1335258540000)/' 这样的字串。
对于这样的格式是无法用来直接展示的,这里可以使用js 做下转换,代码如下
function ChangeDateFormat(DateString) { if (DateString == null) { return "--"; } DateString = DateString.replace("/Date(", "").replace(")/", ""); if (DateString.indexOf("+") > 0) { DateString = DateString.substring(0, DateString.indexOf("+")); } else if (DateString.indexOf("-") > 0) { DateString = DateString.substring(0, DateString.indexOf("-")); } var date = new Date(parseInt(DateString, 10)); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); return date.getFullYear() + "-" + month + "-" + currentDate + " " + date.getHours() + ":" + date.getMinutes(); }