In the project, the front desk Jqgrid in the display of time, there are some problems, find out after the record to meet the same problem people
in the project, the JSON-formatted data was written to Jqgrid, and the data format was converted by Jackson in the background. Jagrid Time Line code is as follows
Java code
- colmodel:[
- {name: 'ID', index:' id ', editable:false, Hidden:True},
- {name:' name ', index:' name ', Label: 'role name', SortType:' text '},
- {name:' createtime ', index:' createtime ', Label: 'creation time ', editable:false,formatter:"Date", Formatoptions: {srcformat:' y-m-d h:i:s ', Newformat:' y-m-d h:i:s '}},
- {name:' CreateBy ', index:' CreateBy ', Label: 'Creator ', sortable:false}
- ],
but in the creation time that line of time shows as "Nan-nan-nan NaN:NaN:NaN", and later only, Jaskson the default time format is time stamp, in Jqgrid, with "U" or "U" to represent the source data timestamp format, So change the above code to read as follows:
Java code
- colmodel:[
- {name: 'ID', index:' id ', editable:false, Hidden:True},
- {name:' name ', index:' name ', Label: 'role name', SortType:' text '},
- {name:' createtime ', index:' createtime ', Label: 'creation time ', editable:false,formatter:"Date", Formatoptions: {srcformat:' u ', Newformat:' y-m-d h:i:s '}},
- {name:' CreateBy ', index:' CreateBy ', Label: 'Creator ', sortable:false} /c0>
- ],
after the change, the number is out, but the display time is too outrageous, shown as: "44235-11-07 21:10:44". Again find information, just know, Jqgrid mainly support this PHP, and PHP and Java in time stamp difference, PHP inside, timestamp with 10 digits, accurate to seconds, Java inside, timestamp with 13 digits, accurate to milliseconds. To view the Jqgrid source code has a paragraph as follows:
Java code
- If(!isnan (Date- 0 ) && String (format). toLowerCase () = = "U") {
- //unix timestamp
- timestamp = new date (parsefloat (date) * );
- }
look again, do not see other processing time stamp place, tracking JS code, for from the background to get the 13-bit timestamp data will also enter here, multiplied by 1000 on the programming of 16, which led to a lot larger than the original time. This paragraph is amended as follows
Java code
- If(!isnan (Date- 0 ) && String (format). toLowerCase () = = "U") {
- //unix timestamp
- timestamp = new date (parsefloat (date));
- }
after the modification, everything appears normal, such as: "2012-04-07 18:13:00",
but think, can not solve the problem so, it means that time to change Jqgrid JS file when the total change this place, modify others source code, still do not know what other problems will appear? Know the problem, then you can find a solution, mainly in which piece of the hand
unexpectedly Jagrid The timestamp has such processing, for Jaskson is used, our project is encapsulated in a tool class inside. Well, I don't give the front desk time stamp data, just as Jackson also provides a way to modify the time data output format, so add a static code, as follows:
Java code
- private static objectmapper mapper = new objectmapper ();
-
- static {
- //jackson The time data written by default is a timestamp, which is modified to the time data output format of the corresponding mode
- mapper.getserializationconfig (). Setdateformat (new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss")) ;
- }
The front page code is as follows:
Java code
- colmodel:[
- {name: 'ID', index:' id ', editable:false, Hidden:True},
- {name:' name ', index:' name ', Label: 'role name', SortType:' text '},
- {name:' createtime ', index:' createtime ', Label: 'creation time ', editable:false,formatter:"Date", Formatoptions: {srcformat:' y-m-d h:i:s ', Newformat:' y-m-d h:i:s '}},
- {name:' CreateBy ', index:' CreateBy ', Label: 'Creator ', sortable:false}
- ],
So after time shows everything normal "2012-04-07 18:13:00"
Jqgrid of time formatting problems