C# 返回json结果集,js日期格式化

asp.net mvc返回json结果集
  1. return Json(new
  2. {
  3. total = totalCount,
  4. rows = result
  5. }, JsonRequestBehavior.AllowGet);
返回的时间格式为"/Date(1381748820000)/"
这个时候在easyui的datagrid列项需要按如下代码进行格式化
  1. title: '手术时间', field: 'OPERATION_DATE_TIME', width: 120
  2. , formatter: function (value, rec) {
  3. if (value == null)
  4. return value;
  5. var date = new Date(parseInt(value.substr(6)));
  6. return date.format("yyyy-MM-dd hh:mm");
  7. }
当然还需要对js的Date扩展format方法。
  1. Date.prototype.format = function (format) {
  2. var o = {
  3. "M+": this.getMonth() + 1, //month
  4. "d+": this.getDate(), //day
  5. "h+": this.getHours(), //hour
  6. "m+": this.getMinutes(), //minute
  7. "s+": this.getSeconds(), //second
  8. "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
  9. "S": this.getMilliseconds() //millisecond
  10. }
  11. if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
  12. (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  13. for (var k in o) if (new RegExp("(" + k + ")").test(format))
  14. format = format.replace(RegExp.$1,
  15. RegExp.$1.length == 1 ? o[k] :
  16. ("00" + o[k]).substr(("" + o[k]).length));
  17. return format;
  18. }





原文地址:https://www.cnblogs.com/zuifengke/p/85a7b26d41848b6e7db7810746d2eec9.html