MVC EasyUI time formatting, mvceasyui

Source: Internet
Author: User

MVC EasyUI time formatting, mvceasyui

Return Json (dr, JsonRequestBehavior. AllowGet); A json data format is returned. When you use EasyUI to output table content, the time output is not the expected format,

The output of the date field is"\/Date (1449046730327 )\/"This format must be converted before output.16:58:50This format,

Some information found on the Internet will be relatively complicated if it is converted through the mvc background. Json is needed. net to reconstruct the json method in mvc. If you don't need it much here, you can search for it online,

Here we will use a front-end js + easyui Extension Method formatter = "Common. DateTimeFormatter"

View ):

<table id="dg" class="easyui-datagrid"  data-options="pageSize:20" pagination="true" rownumbers="true" fit="true" fitcolumns="true" singleselect="true" toolbar="#toolbar" fit="false" style=" height:500px;">    <thead>        <tr>            <th data-options="field:'ck',checkbox:true"></th>            <th field="id">                ID            </th>            <th field="email" >                Email            </th>            <th field="phone" >                phone            </th>            <th field="firstname" >                firstName            </th>            <th field="lastname" >                lastname            </th>             <th field="address" >                Address            </th>            <th field="datecreate" formatter="Common.DateTimeFormatter" >                datecreate            </th>        </tr>    </thead></table>

 

JS:

// EasyUI date formatting Extension Method
1 var Common = {2 // use the DataGrid to format 3 TimeFormatter: function (value, rec, index) {4 if (value = undefined) {5 return ""; 6} 7/* convert json format time to js time format */8 value = value. substr (1, value. length-2); 9 var obj = eval ('+ "{Date: new" + value + "}" + ')'); 10 var dateValue = obj ["Date"]; 11 if (dateValue. getFullYear () <1900) {12 return ""; 13} 14 var val = dateValue. format ("yyyy-mm-dd HH: MM"); 15 return val. substr (11, 5); 16}, 17 DateTimeFormatter: function (value, rec, index) {18 if (value = undefined) {19 return ""; 20} 21/* convert json format time to js time format */22 value = value. substr (1, value. length-2); 23 var obj = eval ('+ "{Date: new" + value + "}" + ')'); 24 var dateValue = obj ["Date"]; 25 if (dateValue. getFullYear () <1900) {26 return ""; 27} 28 return dateValue. format ("yyyy-mm-dd HH: MM: SS"); 29}, 30 31 // use the DataGrid to Format 32 DateFormatter: function (value, rec, index) {33 if (value = undefined) {34 return ""; 35} 36/* convert json format time to js time format */37 value = value. substr (1, value. length-2); 38 var obj = eval ('+ "{Date: new" + value + "}" + ')'); 39 var dateValue = obj ["Date"]; 40 41 if (dateValue. getFullYear () <1900) {42 return ""; 43} 44 45 return dateValue. format ("yyyy-mm-dd"); 46} 47 };

 

 

 

Extended Date Format Method

1 // extend Date to String 2 // month (M), Day (d), hour (H), minute (M) in the specified format), second (S), quarter (q) can use 1-2 placeholders, 3 // year (y) can use 1-4 placeholders, Millisecond (s) only one placeholder (one-three digits) can be used. 4 // example: 5 // (new Date ()). format ("yyyy-mm-dd HH: MM: SS. s ") => 08:09:04. 423 6 // (new Date ()). format ("yyyy-m-d H: M: S. s ") =>. 18 7 Date. prototype. format = function (fmt) {// author: meizz 8 var o = {9 "m +": this. getMonth () + 1, // month 10 "d + ": This. getDate (), // day 11 "H +": this. getHours (), // 12 "M +": this. getMinutes (), // minute 13 "S +": this. getSeconds (), // second 14 "q +": Math. floor (this. getMonth () + 3)/3), // quarter 15 "s": this. getMilliseconds () // millisecond 16}; 17 if (/(y + )/. test (fmt) fmt = fmt. replace (RegExp. $1, (this. getFullYear () + ""). substr (4-RegExp. $1. length); 18 for (var k in o) 19 if (new RegExp ("(" + k + ")"). test (fmt) fmt = fmt. repl Ace (RegExp. $1, (RegExp. $1. length = 1 )? (O [k]): ("00" + o [k]). substr ("" + o [k]). length); 20 return fmt; 21} 22 23 // call: 24 // var time1 = new Date (). format ("yyyy-MM-dd"); 25 // var time2 = new Date (). format ("yyyy-MM-dd HH: mm: ss ");

 

The output result is as follows:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.