EasyUI DataGrid 时间格式化
页面代码:
<table id="tbList" style="height: 340px;" striped="true" rownumbers="true" title="" iconcls="icon-edit" nowrap="false" checkbox="true" idfield="Id" url="@Url.Action("ListData")">
<tr>
<th field="Date" formatter="Common.DateFormatter" width="80">日期</th>
</tr>
</table>
<tr>
<th field="Date" formatter="Common.DateFormatter" width="80">日期</th>
</tr>
</table>
js代码:
var Common = {
//EasyUI用DataGrid用日期格式化
TimeFormatter: function (value, rec, index) {
if (value == undefined) {
return "";
}
/*json格式时间转js时间格式*/
value = value.substr(1, value.length - 2);
var obj = eval('(' + "{Date: new " + value + "}" + ')');
var dateValue = obj["Date"];
if (dateValue.getFullYear() < 1900) {
return "";
}
var val = dateValue.format("yyyy-mm-dd HH:MM");
return val.substr(11, 5);
},
DateTimeFormatter: function (value, rec, index) {
if (value == undefined) {
return "";
}
/*json格式时间转js时间格式*/
value = value.substr(1, value.length - 2);
var obj = eval('(' + "{Date: new " + value + "}" + ')');
var dateValue = obj["Date"];
if (dateValue.getFullYear() < 1900) {
return "";
}
return dateValue.format("yyyy-mm-dd HH:MM");
},
//EasyUI用DataGrid用日期格式化
DateFormatter: function (value, rec, index) {
if (value == undefined) {
return "";
}
/*json格式时间转js时间格式*/
value = value.substr(1, value.length - 2);
var obj = eval('(' + "{Date: new " + value + "}" + ')');
var dateValue = obj["Date"];
if (dateValue.getFullYear() < 1900) {
return "";
}
return dateValue.format("yyyy-mm-dd");
}
};