EasyUI datagrid 序列 化后时间 处理 九

 1 @{
 2     ViewBag.Title = "Home Page";
 3     Layout = null;
 4 }
 5 <!DOCTYPE html>
 6 <html>
 7 <head>
 8     <meta charset="utf-8" />
 9     <meta http-equiv="X-UA-Compatible" content="IE=edge">
10     <title>Page Title</title>
11     <meta name="viewport" content="width=device-width, initial-scale=1">
12     <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
13     <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
14     <script type="text/javascript" src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
15     <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
16 </head>
17 <body>
18     <table id="List" class="easyui-datagrid" style=" auto; height: 350px;"></table>
19 
20     <script>
21         $(function () {
22 
23             $('#List').datagrid({
24                 url: '@Url.Action("GetList")',
25                 method: 'post',
26                 fitColumns: true,
27                 sortName: 'id',
28                 sortOrder: 'asc',
29                 idField: true,
30                 striped: true,
31                 singleSelect: true,
32                 rownumbers: true,
33                 columns: [[
34                     { field: 'id', title: 'ID',  10, align: 'center' },
35                     { field: 'email', title: '注册邮箱',  20, align: 'center' },
36                     { field: 'pwd', title: '密码',  20, align: 'center' },
37                     { field: 'time', title: '登录时间',  20, align: 'center', formatter: formatDate }
38 
39                 ]]
40             });
41         });
42         function PrefixInteger(num, length) {
43             return (Array(length).join('0') + num).slice(-length);
44         }
45         function formatDate(NewDtime) {
46             if (NewDtime == null || NewDtime == "")
47                 return;
48             var dt = new Date(parseInt(NewDtime.slice(6, 19)));
49             var year = dt.getFullYear();
50             var month = PrefixInteger(dt.getMonth() + 1,2);
51             var date = PrefixInteger(dt.getDate(),2);
52             var hour = PrefixInteger(dt.getHours(),2);
53             var minute = PrefixInteger(dt.getMinutes(),2);
54             var second = PrefixInteger(dt.getSeconds(), 2);
55             return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
56         }
57     </script>
58 </body>
59 
60 </html>
1    public JsonResult GetList()
2         {
3             var user = new List<User>
4             {
5                 new User {id=3 ,email="123@qq.com",pwd="123456",time=DateTime.Now },
6                 new User {id=3 ,email="123@qq.com",pwd="123456",time=null }
7             };
8             return   Json(user, JsonRequestBehavior.AllowGet);
9         }
原文地址:https://www.cnblogs.com/LiuFengH/p/10208935.html