Today, when loading data using the Easyui DataGrid in the MVC Framework, the JSON date format returned by the server is/date (1433088000000+0800)/, requires further conversion by the client, and does not conform to the Easyui commonly used date format requirements. , this paper studies the controller under the MVC framework, discovers that the problem can be solved by extending the controller's JSON method,
Today, when loading data using the Easyui DataGrid in the MVC Framework, the JSON date format returned by the server is/date (1433088000000+0800)/. The client needs to be further converted. And also does not conform to Easyui frequently uses the date format request, for this reason, has done some research to the controller under the MVC framework. It is found that the problem can be solved by extending the controller's
When JSON and Java beans are converted to each other, the timestamp field in the bean cannot be processed directly, and two converters need to be implemented.The Datejsonvalueprocessor function is to convert the Timepstamp to the specified time format when the Bean is converted to JSON.1 ImportJava.text.DateFormat;2 ImportJava.text.SimpleDateFormat;3 Importjava.u
Int64 dt = new DateTime (1970, 1, 1). Ticks; The above code already contains C # to JS and JS to C # two parts. On the front end, I can convert C # timestamps to specific times with just the code below:var date=new date (Csharptimetick);Second, directly through the JS processingAfter the datetime of C # is converted to JSON, the default format is this: "/date (1294499956278+0800)/", to convert the time of this format, I just retrieve the middl
Problem:The project uses gson for JSON conversion. However, when processing the date type in the object, the date format is "11:11:11", which is not our expectation "11:11:11 ".
Solution Process:
Search for the solution on the Internet as follows:
Original code: Private Static final gson = new gson ();
New Code: Private Static final gson = new gsonbuilder (). setdateformat ("yyyy-mm-dd hh: mm: SS"). Create ();
After the change, I tested it and it
Function timestamp2string (time) {var datetime = new date (); datetime. settime (time); var year = datetime. getfullyear (); var month = datetime. getmonth () + 1
The time when the database is queried is timestamp, which is encapsulated into the JSON data format. When it is passed to the JSP page through Ajax, it is displayed directly without any processing.[Object object];
The
Gsonbuilder Builder =new Gsonbuilder ();Builder.registertypeadapter (date.class, new jsondeserializerdate> () { Public Date Deserialize (jsonelement json, Type Typeoft, Jsondeserializationcontext context) throws Jsonpa rseexception { return new Date (Json.getasjsonprimitive (). Getaslong ()); } }); Gson Gson =builder.create ();Gson.fromjson (Json,bean);About date type problems in
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.