SPRINGMVC JSON automatically converts the date type to long

Source: Internet
Author: User
Tags time and seconds

Encountered a strange problem this morning, directly to the background to send the request to return the page information displayed in the time is normal, such as: 2016-03-17 15:42:11.0, but the information obtained through Ajax to show the time is actually a timestamp.

I first check the background back to the collection of time type is not the time stamp, the results hit the breakpoint found in the collection display time is also normal, I press F8 Skip, check the browser sent back to JSON corresponding incredibly is time stamp, I do not believe, so repeatedly repeated several times, is indeed a set display normal, A response to the front desk is a timestamp, so I Baidu, give the solution is to add JSON annotations on the time get method of the entity ( @JsonFormat (pattern= "yyyy-MM-dd HH:mm:ss" ,timezone =  "GMT+8" ) ), but I can not use Ah, because this product is not used in the ROM frame, That is, there is no entity this said Ah, depressed after then I think of a way to format it, to see how not.

PrivateList<map<string,object>> FormatDate (list<map<string,object>>list) {List<Map<String,Object>> L =NewArraylist<map<string,object>>();  for(Map<string, object>map:list) {SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); if(Map.get ("Add_time")! =NULL) {String add_time= Map.get ("Add_time"). toString (); Try{Date Date=Sdf.parse (add_time); Map.put ("Add_time", Sdf.format (date)); } Catch(ParseException e) {e.printstacktrace ();        }} l.add (map); }        returnl; }

^_^, after the format is really not converted, I carefully check before I found that the original collection time and seconds after the millisecond 15:42:11.0, the milliseconds to format the JSON will not automatically convert time to timestamp.

To solve this problem successfully!

SPRINGMVC JSON automatically converts the date type to long

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.